OAuth 2.0 Implicit Grant
The Implicit Grant is used to grant access tokens to applications in the authorization response.
You can download sample .NET framework code at https://dl1.empowerid.com/files/OAuthTestSampleCode.zip.
Implicit Grant
-
Initiate a login request to the EmpowerID Authorization endpoint,
https://<EID Server>/oauth/v2/ui/authorizehttps://<EID Server>/oauth/v2/ui/authorize
?client_id=xxxxxxxxxxxxxxxxxx
&redirect_uri=https%3A%2F%2Ftestoauthapp.com%2FcallbackUrl
&response_type=token id_token
&state=xxxxxxxxxxxxxxxxxx
&nonce=xxxxxxxxxxxxxxxxxxPost Body Parameter Required/Optional Description client_idrequired Must be the EmpowerID OAuth application client identifier. redirect_urirequired Client endpoint to which the authorization server should redirect after request approval. response_typerequired Must be tokento initiate implicit flow. For OpenID Connect usetoken id_token.scoperequired for OpenID Connect Include openidfor OpenID Connect flow.staterequired Random string value sent by the client to maintain session and prevent CSRF attacks noncerequired Random string value sent by the client to uniquely identify each request -
Authenticate using either EmpowerID credentials or any of the allowed external identity providers.
-
Authorization server redirects to the
redirect_uriwith the response parameters in the fragment part of URL.redirect_uri
#access_token=xxxxxxxxxxxxxxxxxx
&state=xxxxxxxxxxxxxxxxxx
&token_type=Bearer
&expires_in=3600
&id_token=xxxxxxxxxxxxxxxxxx
Implicit Grant using .NET Client Library
-
Initialize
ClientSettingsby passing theclient_id,client_secret,redirect_uri,token_endpoint,authorization_endpoint,tokeninfo_endpointanduserinfo_endpoint. Also initialize a newImplicitGrantby passing the clientSettings model.var clientSettings = new ClientSettings(
"client_id",
"client_secret",
"redirect_uri",
"https://<EID Server>/oauth/v2/token",
"https://<EID Server>/oauth/v2/ui/authorize",
"https://<EID Server>/oauth/v2/tokeninfo",
"https://<EID Server>/oauth/v2/userinfo");
var handler = new ImplicitGrant(clientSettings); -
Call the
BuildAuthorizationRequestPacket()method to build the fully qualified URL to redirect for authentication.//Generate random nonce and state
var nonce = Guid.NewGuid().ToString("N");
var state = Guid.NewGuid().ToString("N");
//Use the below code for "token" flow to build parameters
var parameters = handler.BuildAuthorizationRequestPacket
(ParameterFormat.FormUrlEncoded, state, null, nonce, null);
//Use the below code for "token id_token" flow to build parameters
//var responseTypes = new List<ResponseType> { ResponseType.id_token };
//var parameters = handler.BuildAuthorizationRequestPacket
//(ParameterFormat.FormUrlEncoded, state, "openid", nonce, responseTypes);
//Generate redirect URL
var redirectUrl = string.Format("{0}?{1}", clientSettings.AuthorizeUrl, parameters); -
In the application callback method, extract the
access_token,id_token, etc., from the fragment part of the redirect URL.