POST https://api.turnkey.com/public/v1/submit/oauth2_authenticate
This URL is shared with the original ACTIVITY_TYPE_OAUTH2_AUTHENTICATE activity. Select V2 with type: ACTIVITY_TYPE_OAUTH2_AUTHENTICATE_V2 and its encrypted payload. Use normal signed API authentication.
Request body
First initialize a target, verify its signature, and encrypt the authentication inputs on the client. Send only the fields above; the authentication inputs travel inside
encryptedMessage.
A target completes one exchange and expires after five minutes. Initialize a new target for each login attempt.
Encrypted payload
Build this JSON object on the client, then encrypt it to the verified enclave target withencryptOauth2ToBundle from @turnkey/crypto. The helper verifies the target’s TLS Fetcher signature, checks that the target was signed for organization_id, and returns the encryptedMessage string and the matching targetPublicKey.
- Fields inside the encrypted object are snake_case; the outer request uses camelCase.
- Set
providertoOAUTH2_PROVIDER_XorOAUTH2_PROVIDER_DISCORD. - Take
organization_id,client_id, andproviderfrom your client configuration. code_verifiermust be 43 to 128 characters fromA-Z,a-z,0-9,-,.,_, and~, as required by PKCE.redirect_urimust be an absolute URI without a fragment.- Compute
nonceassha256(publicKey)over the client session public key, as described in nonce restrictions. It must be 64 lowercase hex characters. Use the same session key for OAuth login. - To receive the provider bearer token, add optional
bearer_token_target_public_key: an uncompressed P-256 public key. Turnkey returns the bearer token encrypted to that key in the OIDC token’sencrypted_bearer_tokenclaim. Omit the field when unused rather than sending an empty string.
Purpose binding
TRANSPORT_ENCRYPTION_SUITE_ENCLAVE_ENCRYPT_V2 adds a purpose binding to the HPKE associated data. The binding contains the purpose ENCRYPTED_INGRESS_PURPOSE_OAUTH2_AUTHENTICATE and the oauth2_credential_id. The enclave rebuilds the binding from the outer parameters.oauth2CredentialId. If that value differs from the credential ID the client encrypted under, decryption fails. This stops a ciphertext from being replayed against a different credential or a different encrypted-ingress activity.
If you encrypt without the helper, verify the target’s TLS Fetcher signature against Turnkey’s production signing key and apply the same purpose binding. Don’t log the unencrypted object.
Result
A completed activity containsactivity.result.oauth2AuthenticateResult.oidcToken. This field is not renamed to oauth2AuthenticateResultV2. SDKs may unwrap the result.
Use the token for existing account lookup, signup, or OAuth login with the same client session key you used to compute the nonce. It is not the final session JWT.
If the provider rejects the exchange, the activity fails with a generic authentication error that doesn’t include provider details.
See social logins for the complete flow.