Obtaining Access Tokens Using Authorization Code Flow
Authorize and authenticate client applications using the OAuth Authorization Code Flow. Get access tokens for Raidiam API access.
For a Sample Postman collection, see the Authorization Code Flow: Obtain Access Token section.
Prerequisites
-
Super User or Data Administrator access to the platform or User Type with appropriate permissions
-
Active and valid Applications (Software Statement) with the scope
directory:website
grantedIf not yet added, Add and Manage Applications.
Make sure your organisation has a Role that enables the organisation resources to request the
directory:website
scope and Add Application Roles. -
Active Transport Certificate
If not yet added, Add Certificate for organisation (shared between apps) or application (associated with a single app only).
-
Active Signing Certificate along with a Public and Private Keys if your application is required to use Signed Request Objects or uses the
private_key_jwt
client authentication method.If not yet added, Add Certificate for organisation (shared between apps) or application (associated with a single app only).
Add .well-known Endpoint
Add Raidiam's Authorisation Server /.well-known
endpoint to your OAuth library configuration.
Your OAuth library should be able to get the server's configuration.
Sample /.well-known
: https://auth.sandbox.raidiam.io/.well-known/openid-configuration
The /.well-known
endpoint contains all the information about the
Authorisation Servers you need to
successfully integrate with the server and get access tokens, for example:
-
Pushed Authorisation Request (PAR) Endpoint:
"pushed_authorization_request_endpoint": "https://auth.sandbox.raidiam.io/request"
-
OAuth Authorization Endpoint:"`authorization_endpoint": "https://auth.sandbox.raidiam.io/auth"
-
OAuth Token Endpoint:
-
"token_endpoint": "https://auth.sandbox.raidiam.io/token"
- for clients authenticating themselves using theprivate_key_jwt
method. -
mTLS Endpoint Aliases - for clients authenticating themselves using the
tls_client_auth
method:
-
"mtls_endpoint_aliases": {
"token_endpoint": "https://matls-auth.sandbox.raidiam.io/token",
"revocation_endpoint": "https://matls-auth.sandbox.raidiam.io/token/revocation",
"introspection_endpoint": "https://matls-auth.sandbox.raidiam.io/token/introspection",
"device_authorization_endpoint": "https://matls-auth.sandbox.raidiam.io/device/auth",
"registration_endpoint": "https://matls-auth.sandbox.raidiam.io/reg",
"userinfo_endpoint": "https://matls-auth.sandbox.raidiam.io/me",
"pushed_authorization_request_endpoint": "https://matls-auth.sandbox.raidiam.io/request",
"backchannel_authentication_endpoint": "https://matls-auth.sandbox.raidiam.io/backchannel"
}
Add Transport Certificate to Application Configuration
[Add Transport Certificate for your organisation]](/docs/how-tos/certificates) and add it to your OAuth library client's configuration.
The Transport Certificate will be used in mutual Transport Layer Security (mTLS) to establish a secure connection between your client and the authorisation server.
Your OAuth client library should be capable of verifying the authorisation server's certificate.
If you are using cURLs to test the integration, you can disable checking the
server's certificate using the -k
flag or --insecure
option.
Scopes in Authorization Code Flow
In OAuth, scope is a mechanism to limit an application's access to a user's account. An application can request one or more scopes. This information:
-
Must be included in the call to the PAR endpoint, OAuth Authorization Endpoint, and OAuth Token Endpoint.
-
Is presented to the user in the consent screen (after the call to the OAuth Authorization Endpoint)
The access token issued to the application is limited to the scopes granted by the user.
In Raidiam, the scopes your application can request are determined by the application's Role and its associated Metadata.
To request the
directory:website
scope, the application needs to have the scope
Role
Metadata Type assigned with the value set to directory:website
.
Note that the application Role is not the value of the scope
parameter.
For Read/Write operations, the scope
parameter value needs to
be directory:website
Prepare Signed Request Object
If needed, prepare a Signed Request Object (RFC9101) with the authorization request parameters.
This step is not required if the Require Signed Request Object option is disabled in advanced Application configuration.
You can check it in Applications > your application > Advanced Configuration view if you are a Super User and the role attached to the Application is of the directory type.
The parameters are represented as the JSON Web Token (JWT) Claims of the
object. Additionally, the JWT should contain the iss
(issuer - your client
ID) and aud
(audience - the authorisation server URL) claims.
{
"client_id": "19283akf98",
"aud": "https://auth.sandbox.raidiam.io",
"iss": "19283akf98",
"exp": 1723734583,
"nbf": 1723734283,
"response_type": "code",
"code_challenge_method": "S256",
"nonce": "gXGldLyaatu",
"scope": "openid trust_framework_profile directory:website",
"claims": {
"id_token": {
"trust_framework_profile": {
"essential": true
}
}
},
"redirect_uri": "https://www.example.com",
"state": "xyaaaABC124",
"code_challenge": "rV7liRb2IT4NYXNLvqrKoazWf9Gb1O3ekIndA8wQLhA",
"response_mode": "query.jwt"
}
To sign the JWT, utilize JSON Web Signature (JWS RFC7515) and a signing key added within your organisation.
Request to PAR Endpoint
Push the contents of the authorization request to the Raidiam's Pushed
Authorization Request (PAR) /requests
endpoint.
Pushed Authorization Requests, defined by the RFC9126specification, enable client applications to push the payload of the authorization request directly to the OAuth Authorisation Server and receive a request URI in exchange -- as a reference to the authorization request payload data in the subsequent call to the authorization endpoint.
Below you can find example requests to the Raidiam's /request
(PAR) endpoint if Signed Request Objects are not required.
- cURL to /request (PAR) Template
- Sample Call with Values
curl --location --request POST 'https://{base_url}/request'\
--cert /path/to/your/certificate.pem \
--key /path/to/your/private.key \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'response_type={response_type}' \
--data-urlencode 'client_id={client_id}' \
--data-urlencode 'scope=[scopes]' \
--data-urlencode 'redirect_uri=[redirect_uris]' \
--data-urlencode 'state={state}' \
--data-urlencode 'code_challenge_method=S256' \
--data-urlencode 'code_challenge={code_challenge}' \
--data-urlencode 'response_mode=query.jwt'
curl --location --request POST 'https://matls-auth.sandbox.directory.openbankingbrasil.org.br/request'\
--cert /path/to/your/certificate.pem \
--key /path/to/your/private.key \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'response_type=code' \
--data-urlencode 'client_id=4674878c-0653-4348-875a-4e99eef993c5' \
--data-urlencode 'scope=directory:website' \
--data-urlencode 'redirect_uri=https://www.example.com' \
--data-urlencode 'state=xyaaaABC124' \
--data-urlencode 'code_challenge_method=S256' \
--data-urlencode 'code_challenge=hipQWZjoA3IpM4ztWKbQwNn_qF3Yx9Tv5s_0iDpQVlw' \
--data-urlencode 'response_mode=query.jwt'
As a response to your request, you receive a request_uri
you can use in the subsequent call to the authorization endpoint.
Request Authorization
-
Redirect the user to the Raidiam's OAuth Authorization
/auth
endpoint including the received request URI and client identifier in the query parameters.Sample URL:
https://{base_url}/auth?request_uri={request_uri}&client_id={client_id}
-
The user authenticates and provides their consent.
Once the user provides their consent, they get redirected back to your application -- to the redirect URL configured for your application.
-
Extract the authorization code from the redirect URL.
Get Token
Call the Raidiam's OAuth /token
endpoint to authenticate your client.
Utilize the client authentication method configured for your client:
-
tls_client_auth -- Mutual-TLS Client Authentication and Certificate-Bound Access Tokens RFC8705
-
private_key_jwt - Assertion Framework for OAuth 2.0 Client Authentication RFC7521
- cURL to /token Template
- Sample Call with Values
curl --location --request POST 'https://{base_url}/token' \
--cert /path/to/your/certificate.pem \
--key /path/to/your/private.key \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'client_id={client_id}' \
--data-urlencode 'code={code}' \
--data-urlencode 'redirect_uri={redirect_uri}' \
--data-urlencode 'code_verifier={code_verifier}'
curl --location --request POST 'https://matls-auth.sandbox.directory.openbankingbrasil.org.br/token' \
--cert /path/to/your/certificate.pem \
--key /path/to/your/private.key \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'client_id=4674878c-0653-4348-875a-4e99eef993c5' \
--data-urlencode 'code=kRmUnYh9rdmf2DxyOLyRTwCjd3uSk6uHmkmioi_98k6' \
--data-urlencode 'redirect_uri=https://www.example.com' \
--data-urlencode 'code_verifier=j03x_D6V86crlIftpUgUUSQoxaTfdt2nfWaHIJpwZEQ'
Upon successful validation of the request, the authorisation server issues and returns an access token - in a form of a JWT signed using the algorithm configured for your client (Applications > your application > Advanced Configuration > Token Signed Response Algorithm ID).
Call Raidiam's APIs
Call Raidiam's APIs using the access token you got from the authorisation server.
By default, applications are configured to receive Certificate Bound
Access Tokens where information about the certificate used to get the
token is included in the token itself and verified by the Raidiam's Resource
Server (APIs).
Make sure to utilize the same certificate across all mTLS connections with the authorisation server and Raidiam's APIs.
Sample Postman Collections for Authorization Code Flow
You can utilize the below Postman Collections to quickly test client authentication for Read/Write Access Tokens:
Import the JSON with collection configuration into Postman and add your Organisation or an Application Transport Certificate to Postman Configuration.
For more information on how to add a certificate in Postman, see the Add and manage CA and Client Certificates in Postman article.