Legacy OAuth Implicit and Password Grants
On this page
FusionAuth supports the Implicit grant and the Password grant for existing integrations. Both grants expose tokens or passwords to more parties than the Authorization Code grant does. Use the Authorization Code grant for new apps.
Implicit Grant#
The Implicit grant returns the access token in the URL fragment, where the token can leak through browser history. The browser also has no safe place to store the token.
The Implicit grant skips the code exchange. FusionAuth returns the access token in the redirect from the authorize endpointThe OAuth 2.0 endpoint where a user logs in and grants an application access. In FusionAuth, the authorization endpoint is /oauth2/authorize.. To use the Implicit grant, enable Implicit in Enabled grants on the OAuth tab of the Application.
Send the Browser to the Authorize Endpoint#
Redirect the browser to the /oauth2/authorize endpoint with response_type set to token. The example adds line breaks for readability.
GET /oauth2/authorize?
client_id=06494b74-a796-4723-af44-1bdb96b48875
&redirect_uri=https%3A%2F%2Fwww.piedpiper.com%2Fcallback
&response_type=token
Host: piedpiper.fusionauth.io
After the user logs in, FusionAuth redirects the browser to the redirect_uri. The parameters, including the access_token, follow the # fragment delimiter:
HTTP/1.1 302 Found
Location: https://www.piedpiper.com/callback#
access_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODUxNDA5ODQsImlhdCI6MTQ4NTEzNzM4NCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiIyOWFjMGMxOC0wYjRhLTQyY2YtODJmYy0wM2Q1NzAzMThhMWQiLCJhcHBsaWNhdGlvbklkIjoiNzkxMDM3MzQtOTdhYi00ZDFhLWFmMzctZTAwNmQwNWQyOTUyIiwicm9sZXMiOltdfQ.Mp0Pcwsz5VECK11Kf2ZZNF_SMKu5CgBeLN9ZOP04kZo
&expires_in=3599
&iss=https%3A%2F%2Fpiedpiper.fusionauth.io
&locale=en
&token_type=Bearer
&userState=Authenticated
For every parameter, see the Implicit grant request.
Password Grant#
With the Password grant, your app collects the user's password and sends the password to FusionAuth. The user also can't log in with FusionAuth features such as social loginLogin through an account the user already has with a consumer service, such as Google or Apple..
The Resource Owner Password Credentials grant, also called the Password grant, exchanges the user's login Id and password for tokens. To use the Password grant, enable Password in Enabled grants on the OAuth tab of the Application.
Exchange the User's Credentials for Tokens#
Send the login Id and the password to the /oauth2/token endpoint with grant_type set to password. To get a refresh token, add offline_access to scope. The example logs in richard@piedpiper.com with the password disrupt, and adds line breaks for readability.
POST /oauth2/token HTTP/1.1
Host: piedpiper.fusionauth.io
Content-Type: application/x-www-form-urlencoded
client_id=06494b74-a796-4723-af44-1bdb96b48875
&client_secret=example-client-secret-do-not-use
&grant_type=password
&password=disrupt
&scope=offline_access
&username=richard%40piedpiper.com
FusionAuth returns the tokens:
{
"access_token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE0ODUxNDA5ODQsImlhdCI6MTQ4NTEzNzM4NCwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiIyOWFjMGMxOC0wYjRhLTQyY2YtODJmYy0wM2Q1NzAzMThhMWQiLCJhcHBsaWNhdGlvbklkIjoiNzkxMDM3MzQtOTdhYi00ZDFhLWFmMzctZTAwNmQwNWQyOTUyIiwicm9sZXMiOltdfQ.Mp0Pcwsz5VECK11Kf2ZZNF_SMKu5CgBeLN9ZOP04kZo",
"expires_in" : 3600,
"refresh_token": "ze9fi6Y9sMSf3yWp3aaO2w7AMav2MFdiMIi2GObrAi-i3248oo0jTQ",
"scope": "offline_access",
"token_type" : "Bearer",
"userId" : "3b6d2f70-4821-4694-ac89-60333c9c4165"
}
Replace example-client-secret-do-not-use with the Client secret from the OAuth tab of your Application. When the Client Authentication of the Application is Not required, leave out client_secret. For when each grant needs the secret, see the Client Secret Reference. For every field, see the Password grant request.
Users With MFA#
When a user has MFA enabled, the Password grant returns a two_factor_required error instead of tokens. The error contains the Id of the MFA challenge and the user's MFA methods. Your app then completes the MFA challenge with the Login API, outside of OAuth. The Login API returns an access token and, when enabled, a refresh token. Your app can use the refresh token with the Token endpoint. For the requests, see Users With MFA in the Token endpoint reference.
Users Without a Registration#
The Password grant authenticates any user in the TenantA logical container for Users, Applications, and settings that is isolated from other Tenants., whether or not the user has a RegistrationThe association between a User and an Application. for the Application. FusionAuth returns tokens to a user without a Registration, including a refresh token when you request offline_access. The access token has an aud claim for the Application, but no applicationId claim and no roles claim.
Require registration to complete OAuth authorization doesn't apply to the Password grant. Self-service registration doesn't create a Registration during a Password grant either. To keep users without a Registration out of your app, check the access token for the applicationId claim, and reject tokens without the claim. For more information, see Authentication and Authorization.
Related
Learn how to log users in with the OAuth Authorization Code grant and PKCE.
Learn how to get an access token for machine-to-machine requests with the OAuth Client Credentials grant.
Learn how to log users in on TVs and other input-constrained devices with the OAuth Device Authorization grant.
Learn about the OAuth 2.0 and OpenID Connect grants FusionAuth supports for login and single sign-on.