PKCE and Public Clients
The default identity provider supports PKCE (RFC 7636) on the authorization code flow. Use it from any app. A mobile app or single-page app that cannot keep a client secret needs it, and also needs its flow set up as a public client.
PKCE on the authorization code flow
- Generate a random
code_verifierof 43 to 128 characters fromA-Z,a-z,0-9,-,.,_and~. - Compute the challenge: the SHA-256 of the verifier, base64url-encoded without padding (43 characters).
- Send the challenge on the authorize request:
https://auth.medbackend.com/oauth/{project_uid}/{entity_type}/authorize
?response_type=code
&client_id=<client_id>
&redirect_uri=<redirect_uri>
&state=<state>
&code_challenge=<challenge>
&code_challenge_method=S256
- Send the verifier with the code to the token endpoint:
POST /oauth/{project_uid}/{entity_type}/token HTTP/1.1
Host: auth.medbackend.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=<code>&redirect_uri=<redirect_uri>&client_id=<client_id>&client_secret=<client_secret>&code_verifier=<verifier>
The challenge is kept across sign-up, e-mail verification, password reset and Sign in with Google, so the code the user comes back with is bound to it whichever path they took.
What is refused
| Request | Result |
|---|---|
code_challenge_method=plain | 400 invalid_request. Only S256 is accepted |
code_challenge without code_challenge_method | 400 invalid_request |
code_challenge_method without code_challenge, or a malformed challenge | 400 invalid_request |
| A code issued with a challenge, redeemed without its verifier or with a wrong one | 400 invalid_grant |
A code_verifier sent for a code that was issued without a challenge | 400 invalid_grant |
PKCE stays optional for a client that sends its secret. A code issued without a challenge is redeemed with the client secret alone.
The provider's OpenID configuration (/.well-known/openid-configuration) lists code_challenge_methods_supported: ["S256"].
Public clients
A public client is an app that cannot keep a secret, such as a mobile app or a single-page app. On a flow set up as a public client, your app leaves out client_secret and proves itself with PKCE instead:
POST /oauth/{project_uid}/{entity_type}/token HTTP/1.1
Host: auth.medbackend.com
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=<code>&redirect_uri=<redirect_uri>&client_id=<client_id>&code_verifier=<verifier>
Without a secret, your app can do only three things:
- redeem a code that was issued with a PKCE challenge, with its matching verifier
- refresh a session that began that way, with
client_idalone. Each refresh returns a new refresh token; store it, because presenting the old one again ends the session - revoke that session's refresh token, with
client_idalone
client_credentials always needs the secret. A request that sends a wrong secret is refused; it is not treated as a public-client request. On a public-client flow, omit client_secret entirely.
You cannot make a flow a public client yourself. Public-client flows are set up by MedBackend support.
The provider's OpenID configuration lists none in token_endpoint_auth_methods_supported.