Before authenticating users, make sure that you have the following information :
  1. OpenID Provider Metadata (autodiscovery URL) : Your admin can provide you with the URL which lives in https://${realm.url}/oauth/${realm.name}/.well-known/openid-configuration
  2. Your client credentials : client_id & client_secret (optional)

Authentication Request

To initiate an authentication request, you must redirect the user browser to the OpenID Provider authorization_endpoint
The parameters available are :
ParameterRequiredDescription
response_typeYesA response_type which has been whitelisted to your client. If the response_type has not been assigned to the client, an error will be returned
client_idYesThe client_id which was provided by your admin
redirect_uriYesOne of the URLs registered by the client. It must be an exact match. If you use a redirect_uri which has not been registered, an error will be returned
scopeNoA space separated list of scopes required for this authentication request. If this parameter is ommited, the default scopes assigned to the client will be used. If a scope is requested and has not been assigned to the client, an error will be returned
stateNoA string that your app creates which the OpenID Provider will return in the response. It's highly recommended to use a state parameter to protect your application against CSRF attacks
code_challengeNoRequired if PKCE enforced is checked on the client. Specifies the SHA256 hash value of the code_verifier value in the token request. Set this parameter to help prevent authorization code interception attacks
code_challenge_methodNoRequired only if you use a code_challenge. CYM-Identity only supports S256
nonceNoRequired only if the response_type includes id_token. A random value which will returned as part of the id_token. It helps to detect replay attacks
response_modeNoSpecify how you expect the Authorization Server to send the response to the redirect_uri. Possible values are query & fragment
promptNoSpecify how the Authorization Server prompts the user for reauthentication and reapproval. Possible values are login, consent, login consent & none
resourceNoSpecify the resource which will be access by the access_tokens from this authentication request. It must equal the URI of a Protected Resource available in the Realm
max_ageNoMaximum Authentication Age. Specifies the allowable elapsed time in seconds since the last time the End-User was actively authenticated. If the elapsed time is greater than this value, the user will be asked to re-authenticate
ui_localesNoA space separated list of languages. Specifies the requested language for the authentication UI. Your login pages must support this parameter or ignore it
acr_valuesNoA space separated list of acr_values. Specifes the authentication levels acceptable to the client. Using this parameters maps to a voluntary OpenID claim
Example request :
https://openid.provider/authorize?
response_type=code&
client_id=YOUR_CLIENT_ID&
redirect_uri=https://your.awesome.app/callback&
scope=openid%20profile&
state=STATE_OF_YOUR_APP

Authentication Response

It may be unusual, but we recommend that you first manage Authentication errors, then authentication success.

Authentication errors

There are two types of errors which can occur on the authentication request

Errors which do not redirect

These errors will mainly happen during your development :
  1. invalid_client_id : The client_id supplied does not match a client from the Realm or the client does not exist
  2. invalid_redirect_uri : The redirect_uri supplied does not match any of the pre-registered redirect_uris

Errors which sends back the user to your app

In case of an error during the authentication, the user will be redirected to your application's redirect_uri as follows :
https://my.awesome.app/callback?
error=ERROR_NAME&
error_description=ERROR_DETAILS&
state=YOUR_APP_STATE
ParameterRequiredDescription
errorYesAn error code which can be used by your app to determine the reason of the error
error_descriptionNoA description which can be used by the developer to fix the error
stateNoIf a state parameter is present in the request, it'll be echoed in the response
The possible errors are summarized below :
ErrorSource
invalid_response_typeThe response_type requested is not whitelisted for the app
invalid_scopeThe scope requested does not exist or has not been assigned to the client
invalid_response_modeThe response_mode requested is not whitelisted for the app or does not exist
invalid_code_challengeThe code_challenge is missing from the request
invalid_code_challenge_methodThe code_challenge_method is missing from the request
nonce_requiredIn case an id_token will be directly passed to the redirect_uri, a nonce is required in the request
access_deniedThe user did not consent to the scopes requested by the App
login_requiredIn case of a request with prompt=none, this error will be returned if the user is not logged in, or if the max_age has ellapsed
invalid_requestThe resource requested does not exist or the scopes requested are not sufficient for the resource

Authentication Success

In case of a successful authentication, the user will be redirected to the specified redirect_uri as follows :
https://my.awesome.app/callback#
code=A_RANDOMLY_GENERATED_CODE&
access_token=AN_ACCESS_TOKEN&
id_token=AN_ID_TOKEN&
scope=openid%20profile&
expires_in=3600&
session_state=A_STATE_STATE&
state=YOUR_APP_STATE&
token_type=Bearer
ParameterRequiredDescription
codeNoWill be present if the requested responsetype included _code
access_tokenNoWill be present if the requested responsetype included _token
id_tokenNoWill be present if the requested responsetype included _id_token
stateNoIf a state parameter is present in the request, it'll be echoed in the response
scopeNoA scope will be returned if the requested response_type included token
expires_inNoWill be returned if the requested response_type included token. Represents the number of seconds the access_token is valid for.
session_stateNoA string which must be used to listen to session change events Session.
token_typeNoWill be returned if the requested response_type included token. Represents the type of access token returned. Only Bearer access_tokens are supported

Authorization Code Exchange

In case you requested a code, you need to exchange this code for the actual tokens. You'll call the Authorization Server token_endpoint

Authorization Code request

POST /token_endpoint HTTP/1.1
Host: oauth.server
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=A_RANDOMLY_GENERATED_CODE
&redirect_uri=https%3A%2F%2Fyour.awesome.app%2Fcallback
&client_id=YOUR_CLIENT_ID
&client_secret=YOUR_CLIENT_SECRET
ParameterRequiredDescription
grant_typeYesThe value must be authorization_code
codeYesthe code received in your redirect_uri
redirect_uriYesThe redirect_uri which your app received the code on
client_idNoOnly required if the client authenticates through client_secret_post or does not authenticate (for native clients)
client_secretNoOnly required if the client authenticates through client_secret_post
client_assertionNoOnly required if the client authenticated through client_secret_jwt or private_key_jwt
client_assertion_typeNoOnly required if a clientassertion is used. The value must be _urn:ietf:params:oauth:client-assertion-type:jwt-bearer
code_verifierNoOnly required if a code_challenge was used during the authentication request
resourceNoThe URI of a resource which has been declared in the Realm

Authorization Code response

Error response

HTTP/1.1 400 Bad Request
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
"error": "AN_ERROR_CODE",
"error_description": "AN_ERROR_DESCRIPTION"
}

Successful response

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache
{
"access_token": "AN_ACCESS_TOKEN_VALUE",
"id_token" : "AN_ID_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token" : "A_REFRESH_TOKEN"
}