There's a new version of Comply One API! We strongly-recommend to start migrating your API Clients as this version will not be supported in the near future. Please review the new version and read the Migration Guides
New Version Migration GuidesThe Proof Key for Code Exchange (PKCE) flow is a variant of Authorization Code flow. However, it provides another level of security by requiring the API Client to include a temporary secret (Code Challenge) in the Authentication Request and a secret verifier (Code Verifier) in the Token Request.
This authentication flow is more secured than the Authorization Code flow because it provides the means to ensure the authorization code received from Stems Accounts is verifiable. For this reason, this Authentication Flow is highly-recommended for native mobile applications and desktop applications, as long as these applications are built using native code (as in, not HTML5 applications).
To request an Access Token using the PKCE (pronounced pixie) flow, the API Client should perform the following steps:
Before the API Client issues the Authentication Request to Stems Accounts, it needs to generate a code verifier and a code challenge.
The code verifier is simply a random string. The only requirement is that the code verifier needs to be randomly-generated with a minimum length of 43 characters and a maximum length of 128 characters. This will then be used to generate a code challenge and to verify the Authorization Code received from the Authentication Response.
The value of the code challenge can vary based on the code_challenge_method parameter sent in the Authentication Request. If the code_challenge_method parameter can only have one of two values:
When setting the code_challenge_method parameter to S256 in the Authentication Request, you need to first create a hash of the code verifier using the SHA-256 Algorithm and then convert the hash to a Base64Url-encoded string:
BASE64URL-ENCODE(SHA256(ASCII(code_verifier))) == code_challenge
Stems Accounts will associate the code challenge (received from the API Client in the Authentication Request) with the Authorization Code. Then, when the API Client issues the Token Request, Stems Accounts will attempt to match the code verifier with the code challenge received in the Authentication Request.
When using the PCKE flow, your API Client should open a browser session and redirect the user to Stems Accounts' Authorization Endpoint. The Authentication Request is very similar to that of the Authorization Code flow. The only difference is that the response_type parameter must be set to code. The following parameters MUST be also included:
Parameter | Description |
---|---|
code_challenge | Required. Refer Creating a Code Challenge for more information |
code_challenge_method | Optional. This can be set to plain or S256. If ommitted, the behaviour is the same as when set to plain. Refer Creating a Code Challenge for more information |
A typical request to the Authorization Endpoint would look like the following example:
GET /auth/connect/authorize?
client_id=YOUR_CLIENT_ID
&response_type=code
&redirect_uri=http%3A%2F%2Flocalhost%3A9595
&scope=openid+email+profile+roles
&response_mode=form_post
&state=MdNEdpV8mOT0dpzyfEnXklRmTTdWd2ek
&nonce=irr6Jltaqol9sUXwVKz8tlY1JlWQR5Bz
&code_challenge=I6hp0P4knRHxDxcpqPjLzvfhlYRq3CWBPJddasRDsA
&code_challenge_method=S256 HTTP/1.1
Host: accounts.stems.com.au
If the request to the Authorization Endpoint is successful, Stems Accounts will issue a POST request to the url specified in the redirect_uri with the Authorization Code in the body of the request if the response_form was present in the authentication request.
The body of the response from Stems Accounts will include the following form data:
Field | Description |
---|---|
code | The Authorization Code that the API Client can use to exchange it for an ID Token, Access Token and optionally a Refresh Token |
state | If the state parameter was provided in the request to the authorization endpoint, API Clients MUST verify that this value matches the one provided in the authentication request |
session_state | The current session's state |
When the response_form is not included in the authentication request, Stems Accounts will redirect back to the redirect_uri with the Authorization Code included in the url query string as in the example below:
GET /?code=85ff37999de045455b6eea8f194235fe
&state=345G2KJHG32JK5G34KLH2F46HK
&session_state=59306c731065bd5bef7d78ec90b4dc5a HTTP/1.1
Host: contoso.com
The Authorization Endpoint could return errors if the API Client is not setup properly or the request had invalid or missing parameters. When an error occurs, the Authorization Endpoint will return to the API Client's redirect_uri with an error parameter containing an error code and an optional error_description fragment parameter with details about the error.
Once the Authorization Code has been received from Stems Accounts, the API Client can issue a POST request to the Stems Accounts' Token Endpoint.
The request to the Token Endpoint is similar to that of the Authorization Code flow. The only difference is that the request MUST also include a code_verifier parameter with the Code Verifier. See Creating a Code Challenge for more information about the Code Verifier value.
Once the API Client has received the ID Token, it is strongly recommended that it is validated to make sure it hasn't been tampered with. Refer to ID Token Validation of the Authorization Code section to learn how to validate an ID Token.