Implicit Grant
- Endpoints
The Implicit grant is designed for public clients that run inside the resource owner's user-agent, for example, JavaScript applications.
Since applications running in the user-agent are considered less trusted than applications running in servers, the authorization server will never issue refresh tokens in this flow. Also, you must consider the security impact of cross-site scripting (XSS) attacks that could leak the access token to other systems, and implement Cross-Origin Resource Sharing (CORS) to make OAuth 2.0 requests to different domains.
Due to the security implications of this flow, it is recommended to use the Authorization Code grant with PKCE flow whenever possible.
The steps in the diagram are described below:
The client, usually a single-page application (SPA), receives a request to access a protected resource. To access the resources, the client requires authorization from the resource owner.
The client redirects the resource owner's user-agent or opens a new frame to the AM authorization service.
The authorization server authenticates the resource owner, confirms resource access, and gathers consent if not previously saved.
If the resource owner's credentials are valid, the authorization server returns the access token to the user-agent as part of the redirection URI.
Now, the client must extract the access token from the URI. In this example, the user-agent follows the redirection to the web-hosted server that contains the protected resources without the access token....
...And the web-hosted server returns a web page with an embedded script to extract the access token from the URI.
In another possible scenario, the redirection URI is a dummy URI in the client, and the client already has the logic in itself to extract the access token.
The user-agent executes the script and retrieves the access token.
The user-agent returns the access token to the client.
The client requests access to the protected resources presenting the access token to the resource server.
The resource server contacts the authorization server to validate the access token.
The authorization server validates the token and responds to the resource server.
If the token is valid, the resource server allows the client to access the protected resources.
Perform the steps in the following procedures to obtain an access token:
This procedure assumes the following configuration:
AM is configured as an OAuth 2.0 authorization server. Ensure that:
The
token
plugin is configured in the Response Type Plugins field.The
Implicit Grant
grant type is configured in the Grant Types field.
For more information, see Authorization Server Configuration.
A public client called
myClient
is registered in AM with the following configuration:Scopes:
write
Response Types:
token
Grant Types:
Implicit
For more information, see Client Registration.
Perform the steps in this procedure to obtain an access token using the Implicit grant:
The client makes a GET call to the authorization server's authorization endpoint specifying, at least, the following parameters:
client_id=your_client_id
response_type=token
redirect_uri=your_redirect_uri
For information about the parameters supported by the
/oauth2/authorize
endpoint, see "/oauth2/authorize".If the OAuth 2.0 provider is configured for a subrealm rather than the Top Level Realm, you must specify it in the endpoint. For example, if the OAuth 2.0 provider is configured for the
/customers
realm, then use/oauth2/realms/root/realms/customers/authorize
.For example:
https://openam.example.com:8443/openam/oauth2/realms/root/authorize \ ?client_id=myClient \ &response_type=token \ &scope=write \ &redirect_uri=https://www.example.com:443/callback \ &state=abc123
Note that the URL is split for readability purposes and that the
scope
andstate
parameters have been included. Scopes are not required, since they can be configured by default in the authorization server and the client, and have been added only as an example. Thestate
parameter is added to protect against CSRF attacks. Also, the redirection URI was not specified, and the URI defined in the client profile is used by default.The resource owner logs in to the authorization server, for example, using the credentials of the
demo
user. In this case, they log in using the default chain or tree configured for the realm.After logging in, the authorization server presents the AM user interface consent screen:
The resource owner selects the
Allow
button to grant consent for thewrite
scope.The authorization server redirects the resource owner to the URL specified in the
redirect_uri
parameter.Inspect the URL in the browser. It contains an
access_token
parameter with the access token the authorization server has issued. For example:https://www.example.com:443/callback#access_token=1i5IfaebiLnpyxFM4mcTSZSegb4&scope=write&redirect_uri%3Dhttps%3A%2F%2Fwww.example.com%3A8443%2Fcallback&iss=https%3A%2F%2Fopenam.example.com%3A8443%2Fopenam%2Foauth2&state=abc123&client_id=myClient
This procedure assumes the following configuration:
AM is configured as an OAuth 2.0 authorization server. Ensure that:
The
token
plugin is configured in the Response Type Plugins field.The
Implicit Grant
grant type is configured in the Grant Types field.
For more information, see Authorization Server Configuration.
A public client called
myClient
is registered in AM with the following configuration:Scopes:
write
Response Types:
token
Grant Types:
Implicit
For more information, see Client Registration.
Perform the steps in this procedure to obtain an access token using the Implicit grant:
The resource owner authenticates to the authorization server, for example, using the credentials of the
demo
user. For example:$
curl \ --request POST \ --header "Content-Type: application/json" \ --header "X-OpenAM-Username: demo" \ --header "X-OpenAM-Password: Ch4ng31t" \ --header "Accept-API-Version: resource=2.0, protocol=1.0" \ 'https://openam.example.com:8443/openam/json/realms/root/authenticate'
{ "tokenId":"AQIC5wM...TU3OQ*", "successUrl":"/openam/console", "realm":"/" }
The client makes a POST call to the authorization server's authorization endpoint, specifying the SSO token of the
demo
in a cookie and, at least, the following parameters:client_id=your_client_id
response_type=token
decision=allow
csrf=demo_user_SSO_token
redirect_uri=your_redirect_uri
For information about the parameters supported by the
/oauth2/authorize
endpoint, see "/oauth2/authorize".If the OAuth 2.0 provider is configured for a subrealm rather than the Top Level Realm, you must specify it in the endpoint. For example, if the OAuth 2.0 provider is configured for the
/customers
realm, then use/oauth2/realms/root/realms/customers/authorize
.For example:
curl --dump-header - \ --Cookie "iPlanetDirectoryPro=AQIC5wM...TU3OQ*" \ --request POST \ --data "client_id=myClient" \ --data "response_type=token" \ --data "scope=write" \ --data "state=123abc" \ --data "decision=allow" \ --data "csrf=AQIC5wM...TU3OQ*" \ --data "redirect_uri=https://www.example.com:443/callback" \ "https://openam.example.com:8443/openam/oauth2/realms/root/authorize"
Note that the
scope
andstate
parameters have been included. Scopes are not required, since they can be configured by default in the authorization server and the client, and have been added only as an example. Thestate
parameter is added to protect against CSRF attacks.If the authorization server is able to authenticate the user, it returns an HTTP 302 response with the access token appended to the redirection URI:
1.1 302 Found Server: Apache-Coyote/1.1 X-Frame-Options: SAMEORIGIN Pragma: no-cache Cache-Control: no-store Date: Wed, 22 Aug 2018 11:19:54 GMT Accept-Ranges: bytes Location: https://www.example.com:443/callback#access_token=PAsODWCvnb5W8uuBT12H62Rvmro&scope=write&redirect_uri%3Dhttps%3A%2F%2Fwww.example.com%3A8443%2Fcallback&iss=https%3A%2F%2Fopenam.example.com%3A8443%2Fopenam%2Foauth2&state=123abc&token_type=Bearer&expires_in=3599&client_id=myClient Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept Content-Length: 0
In this case, the redirection URI was not specified in the command, and the URI defined in the client profile is used by default.