#
Authorization code grant flow with proof key for code exchange
#
Introduction
Proof Key for Code Exchange (PKCE) is an extension to the Authorization Code Flow to prevent CSRF and authorization code injection attacks.
PKCE is not a form of client authentication, and PKCE is not a replacement for a client secret or other client authentication. PKCE is recommended even if a client is using a client secret.
This flow was originally designed to protect the authorization code flow in mobile applications. However, its ability to prevent authorization code injection makes it useful for every type of OAuth client, including web apps that use client authentication.
For web applications, the client secret must be managed in a secure store or wallet within the client application to obtain the token pair for an issued authorization code.
It consists of the steps found below.
#
Step 1: Authorizing the user
The URL of the Pagero Login page is:
Request method: GET
Required query parameters:
Optional query parameters:
#
Example
#
Step 2: Obtaining authorization code
Upon successful login, the authorization_code
is posted back as a query parameter to the URL defined in the redirect_uri
query parameter.
Response structure:
#
Example
- https://urltoclient:4443/?code=0F7ijeaW4BCwhvyg6ozY9PeLsFF6KUi1&state=exampleState&iss=https%3A%2F%2Fauthorization-server.com
#
Step 3: Exchanging to a token
Using the authorization_code
, the code_verifier
, and the client_secret
, it’s now possible to obtain an access_token
and a refresh_token
.
The URL for doing so is:
Request method: POST
Required parameters in application/x-www-form-urlencoded
:
Required headers (if not client_id
and client_secret
provided in the body):
Response structure:
#
Example with header option
curl https://sso.pageroonline.com/oauth/v2/oauth-token \
-d grant_type=authorization_code \
-d code=0F7ijeaW4BCwhvyg6ozY9PeLsFF6KUi1 \
-d redirect_uri=https://urltoclient:4443 \
-d code_verifier=xyz12345 \
--user 'client-id:client-secret'
The response will contain a JSON body that looks like this:
{
"token_type": "bearer",
"access_token": "_0XBPWQQ_2a66dd33-e108-4dc3-b653-e71b9feae02e",
"refresh_token": "_1XBPWQQ_e61b091b-9139-4268-a7c7-765d2d418d52",
"scope": "",
"claims": "publicid",
"expires_in": 600
}
#
Making an API request using an access token
When making an API request, the access token should be provided in an Authentication header as a bearer token.
curl https://api.pageroonline.com/someresource \
-H 'Authorization: Bearer _0XBPWQQ_2a66dd33-e108-4dc3-b653-e71b9feae02e'