This tutorial will help you call your own API using the Authorization Code Flow. If you want to learn how the flow works and why you should use it, see Authorization Code Flow. If you want to learn to add login to your regular web app, see Add Login Using the Authorization Code Flow.
Auth0 makes it easy for your app to implement the Flow using:

Prerequisites

Before beginning this tutorial:
  • Register your Application with Auth0.
    • Select an Application Type of Regular Web Apps.
    • Add an Allowed Callback URL of {https://yourApp/callback}.
    • Make sure your Application’s Grant Types include Authorization Code. To learn how, read Update Grant Types.
    • If you want your Application to be able to use refresh tokens, make sure the Application’s Grant Types include refresh token. To learn how, read Update Grant Types. To learn more about Refresh Tokens, read refresh tokens.
  • Register your API with Auth0
    • If you want your API to receive refresh tokens to allow it to obtain new tokens when the previous ones expire, enable Allow Offline Access.

Steps

Sample use cases

Customize tokens

You can use Auth0 Actions to modify the scopes of an and/or add custom claims to access and . To learn more about Actions, see Understand how Auth0 Actions Work. To do so, add the following Post-Login Action, which will run after the user authenticates:
exports.onExecutePostLogin = async (event, api) => {
  // Add custom claims to Access Token and ID Token
  api.accessToken.setCustomClaim('https://foo/bar', 'value');
  api.idToken.setCustomClaim('https://fiz/baz', 'some other value');

  // Modify the scope of the Access Token
  api.accessToken.addScope('foo');
  api.accessToken.addScope('bar');
};
Auth0 returns profile information in a structured claim format as defined by the OpenID Connect (OIDC) specification. This means that custom claims added to ID tokens or access tokens must conform to guidelines and restrictions to avoid possible collisions.

Learn more