Configuring tokens - Azure Active Directory B2C (2023)

  • Article

before you start, UseSelect a policy typeUse the selector to select the type of policy you want to configure. Azure Active Directory B2C provides two methods for defining how users interact with applications: using predefined onesuser flowsor fully customizablecustom rules. The steps required in this article are different for each method.

This article will show you how to set it upToken lifetime and compatibilityim Azure Active Directory B2C (Azure AD B2C).


  • Create a user flowto allow users to register and log in to your application.
  • Register the web application.
  • Follow the instructions inStart with custom policies in Active Directory B2C
  • Register the web application.

Behavior during the life of the token

You can configure the token lifetime, including:

(Video) Azure Active Directory B2C Token Generation With No User Interaction [GCAST 116]

  • Access token and ID lifetime (minutes)- Lifetime of the OAuth 2.0 bearer token and ID tokens. The default is 60 minutes (1 hour). The minimum duration (inclusive) is 5 minutes. The maximum (inclusive) is 1440 minutes (24 hours).
  • Refresh token lifetime (days)- Maximum time a refresh token can be used to get a new access token if your app has been grantedoffline_accessRange. The default value is 14 days. The minimum (inclusive) is one day. Maximum (inclusive) 90 days.
  • Update the lifetime of the sliding token window- Token refresh sliding window type.LimitedIndicates that the refresh token can be extended as specified in the fileLifetime (days).indefinitelySpecifies that the refresh token sliding window lifetime never expires.
  • Lifetime (days)- After this time, the user must reauthorize, regardless of the validity period of the last refresh token obtained by the application. The value must be greater than or equal toRefresh token lifetimeWert.

The following diagram shows the lifetime behavior of the sliding refresh token window.

Configuring tokens - Azure Active Directory B2C (1)


Single page apps that use the authorization code flow with PKCE always have a refresh token lifetime of 24 hours, while mobile apps, desktop apps, and web apps do not have this limit.Learn more about the security impact of browser refresh tokens.

Configure the token lifetime

To configure the user flow token lifetime:

(Video) How to configure basic policies in Azure Active Directory B2C | Azure Active Directory

  1. Log inAzure-Portal.
  2. Make sure you're using the directory that contains your Azure AD B2C tenant. To chooseCatalogs + SubscriptionsPortal toolbar icon.
  3. AlreadyPortal Settings | Catalogs + SubscriptionsOn the Your Azure AD B2C Directory page, locate the filedirectory namelist, then selectswitch.
  4. To chooseAll servicesin the upper left corner of the Azure portal, then search and selectAzure AD B2C.
  5. To chooseUser flows (policies).
  6. Open the user flow you created earlier.
  7. To chooseCharacteristic.
  8. Podtoken lifetime, adjust the properties to the needs of your application.
  9. To chooseSave to your computer.

Configuring tokens - Azure Active Directory B2C (2)

To change token compliance settings, setToken issuertechnical profile metadata in the policy extension or relying party file you want to affect. The technical profile of the token issuer looks like in the example below:

  Token issuer    3600 3600 1209600 7776000  Authorities and TenantGuid Nic    

In the previous example, the following values ​​were set:

  • token_lifetime_secs- Access token lifetime (seconds). The default value is 3600 (1 hour). The minimum is 300 (5 minutes). The maximum is 86,400 (24 hours).
  • id_token_lifetime_secs- Identification token lifetime (seconds). The default value is 3600 (1 hour). The minimum is 300 (5 minutes). The maximum is 86,400 (24 hours).
  • fresh_token_lifetime_secsRefresh token lifetime (seconds). The default value is 1,209,600 (14 days). The minimum is 86,400 (24 hours). The maximum is 7,776,000 (90 days).
  • Rolling_refresh_token_lifetime_secs- Refresh the lifetime of the sliding token window (seconds). The default value is 7,776,000 (90 days). The minimum is 86,400 (24 hours). The maximum is 31,536,000 (365 days). If you don't want to enforce the lifetime of the sliding window, set the valueAllow_infinite_rolling_refresh_tokenDoTRUE.
  • Allow_infinite_rolling_refresh_token- The lifetime of the sliding token refresh window never expires.

Token compliance settings

You can configure token compatibility including:

  • Issuer claim (iss).- Access token and ID issuer format.
  • (sub)claim in question– The principal about whom the token provides information, e.g. B. application user. This value is immutable and cannot be reassigned or reused. Can be used to perform authorization checks securely, such as when a token is used to access a resource. By default, the subject claim is populated with the user's object ID in the directory.
  • A declaration representing the flow of users– This claim identifies the running user flow. Possible value:tfp(Default) oracre.

To configure user flow compliance settings:

(Video) How to Retrieve an OAuth 2.0 Access Token from Azure Directory B2C (Implicit Flow)

  1. To chooseUser flows (policies).
  2. Open the user flow you created earlier.
  3. To chooseCharacteristic.
  4. PodToken compliance settings, adjust the properties to the needs of your application.
  5. To chooseSave to your computer.

To change token compliance settings, setToken issuertechnical profile metadata in the policy extension or relying party file you want to update. The technical profile of the token issuer looks like in the example below:

  Token issuer   ...Authorities and TenantGuid Nic    
  • Issuer claim (iss).- the issuer's claim (iss) will be written off as ofIssuance request patternmetadata item. Valid values ​​areAuthorities and TenantGuidIPermissions from Tfp.

  • Set a claim that represents the policy ID- The options available to set this value areTFP(Trust Framework Directive) iACR(Authentication context reference).TFPis the recommended value. OpinionAuthenticationContextReferenceClaimPatternwith valuenic.

    I amScheme of statementsitem, add this item:

     The name of the Trust Framework policy string

    In yoursRelying Party Policy, podExit claimsAdd item, add the following output statement:

    For ACR, delete the fileAuthenticationContextReferenceClaimPatternArticle.

    (Video) Creating an Azure Active Directory B2C Tenant [GCast 114]

  • (sub)claim in question– This option defaults to ObjectID if you want to change this setting toNot supported, replace this line:

    with this line:

Provide optional claims for your app

Application claims are the values ​​returned to the application. Update the user flow to include the requested claims.

  1. To chooseUser flows (policies).
  2. Open the user flow you created earlier.
  3. To chooseApplication Claims.
  4. Select the claims and attributes you want to send back to your app.
  5. To chooseSave to your computer.

TheRelying party policy technical profileOutput claims are the values ​​returned to the application. With the addition of output claims, after a successful user journey, claims are output in a token and sent to the application. Modify the technical profile element in the Relying party section to add the desired claims as the output claim.

  1. Open the custom policy file. For example, SignUpOrSignin.xml.
  2. Find the OutputClaims item. Add the OutputClaim to be included in the token.
  3. Set the output request attributes.

The example below addsbank balancelaw. The AccountBalance claim is sent to the app as a balance.

(Video) .NET Core Step-by-Step Guide: Configuring Azure AD B2C Authentication for a Web App and Web API

   Policy profile   < OutputClaim ClaimTypeReferenceId="givenName" />   < OutputClaim ClaimTypeReferenceId="tenantId" AlwaysUseDefaultValue="true" DefaultValue="{Policy:TenantObjectId}" />    

The OutputClaim element contains the following attributes:

  • Claim type reference ID– Claim type ID that is already defined in the fileScheme of statementsA section in a policy file or parent policy file.
  • Partner claim type- Allows you to rename the claim in the token.
  • default value– Default value. You can also set the default value to aclaims adjusterSuch as B. Tenant ID.
  • AlwaysUseDefaultValue- Force use of default value.

Authorization code lifetime

When usingOAuth 2.0 authorization code expiredthe application can use the authorization code to request an access token for the target resource. Authorization codes are short-lived and expire after approximately 10 minutes. Authorization code expiration is not configurable. Make sure your app redeems the authorization codes within 10 minutes.

Next steps

  • Find out more about itRequest an access token.
  • Learn how to buildResilience with developer best practices.


How do I get an Azure B2C access token? ›

A registered application receives tokens and communicates with Azure AD B2C by sending requests to these endpoints: https://<tenant-name><tenant-name><policy-name>/oauth2/v2.0/authorize. https://<tenant-name><tenant-name><policy-name>/oauth2/v2.0/token.

What is the token lifetime in Azure AD B2C? ›

Token lifetime behavior

The default is 60 minutes (1 hour). The minimum (inclusive) is 5 minutes. The maximum (inclusive) is 1,440 minutes (24 hours).

How do I get a refresh token in Azure B2C? ›

The following are the basic steps to use the OAuth 2.0 authorization code grant flow to get a refresh token from the Microsoft identity platform endpoint:
  1. Register your app with Azure AD.
  2. Get authorization.
  3. Get a refresh token.
Apr 14, 2023

What is the difference between access token and ID token in B2C? ›

Access tokens are what the OAuth client uses to make requests to an API. The access token is meant to be read and validated by the API. An ID token contains information about what happened when a user authenticated, and is intended to be read by the OAuth client.

How do I create an Azure AD access token? ›

There are two steps to acquire an Azure AD access token using the authorization code flow.
  1. Request an authorization code, which launches a browser window and asks for Azure user login. The authorization code is returned after the user successfully logs in.
  2. Use the authorization code to acquire the Azure AD access token.
6 days ago

Is Azure AD B2C deprecated? › will be deprecated for Azure Active Directory B2C on 31 August 2022. This does not impact Azure Active Directory (Azure AD) tenants, only B2C. More information:

How does Azure B2C authentication work? ›

Azure AD B2C provides various ways in which you can authenticate a user. Users can sign-in to a local account, by using username and password, phone verification (also known as password-less authentication). Email sign-up is enabled by default in your local account identity provider settings.

What is the maximum token size in Active Directory? ›

The maximum allowed value of MaxTokenSize is 65535 bytes.

What is the difference between access token and refresh token? ›

The difference between a refresh token and an access token is the audience: the refresh token only goes back to the authorization server, the access token goes to the (RS) resource server. Also, just getting an access token doesn't mean the user's logged in.

What is the difference between refresh token and ID token? ›

Refresh token is a long-lived special kind of token used to obtain a renewed access token. ID token carries identity information encoded in the token itself, which must be a JWT. It must not contain any authorization information, or any audience information — it is merely an identifier for the user.

How long does Azure AD access token last? ›

The default Azure AD access token lifetime varies between 60 and 90 minutes (75 minutes on average).

What is the difference between Azure AD and Azure AD B2C? ›

Azure AD is Microsoft's solution for managing employee access to SaaS apps and it has features designed for this purpose such as licensing and Conditional Access. Azure AD B2C provides an identity and access management platform for building web and mobile applications.

What is the difference between Azure Active Directory and Active Directory B2C? ›

Azure AD B2C is a separate service from Azure Active Directory (Azure AD). It is built on the same technology as Azure AD but for a different purpose. It allows businesses to build customer facing applications, and then allow anyone to sign-up and into those applications with no restrictions on user account.

What is the difference between Azure Active Directory B2B and B2C? ›

There are differences with Azure AD B2B and B2C when it comes to customisation. With B2B, the hosting organisation's branding is automatically applied, whereas, with B2C, the branding and customisation sit within the application's team. API Integration for customer journeys is much more flexible on B2C.

How do I refresh my Azure token? ›

Go to Services > Applications > Azure Cloud Solution Provider > instance name > Configuration tab > Manage Refresh Token. In the Manual Update group, specify the authorization code that you received and click Update.

How do I request a refresh token? ›

To get a refresh token, you send a request to your Okta authorization server. The only flows that support refresh tokens are the authorization code flow and the resource owner password flow.

How do I verify my Azure AD token? ›

The validate-azure-ad-token policy enforces the existence and validity of a JSON web token (JWT) that was provided by the Azure Active Directory service. The JWT can be extracted from a specified HTTP header, query parameter, or value provided using a policy expression or context variable.

How do Azure tokens work? ›

An access token contains claims that you can use in Azure Active Directory B2C (Azure AD B2C) to identify the granted permissions to your APIs. To call a resource server, the HTTP request must include an access token. An access token is denoted as access_token in the responses from Azure AD B2C.

How do I manually create an access token? ›

In the upper-right corner of any page, click your profile photo, then click Settings. In the left sidebar, click Developer settings. In the left sidebar, under Personal access tokens, click Tokens (classic). Select Generate new token, then click Generate new token (classic).

How do I generate access tokens? ›

Basic steps
  1. Obtain OAuth 2.0 credentials from the Google API Console. ...
  2. Obtain an access token from the Google Authorization Server. ...
  3. Examine scopes of access granted by the user. ...
  4. Send the access token to an API. ...
  5. Refresh the access token, if necessary.
Mar 6, 2023

How do I secure my Azure AD B2C? ›

Validate secure API access
  1. In the Azure portal, go to your Azure AD B2C tenant.
  2. Under Policies, select User flows.
  3. Select an existing sign-up/sign-in user flow (for example, B2C_1_signupsignin1).
  4. For Application, select webapp1.
  5. Select Run user flow.
  6. Record the encoded token value that's displayed in your browser.
Jan 9, 2023

What are the benefits of Azure AD B2C? ›

Azure AD B2C provides a simple and convenient way for customers to access your applications without having to remember dozens of individual login details. Single Sign-On (SSO) adds security and convenience when users can sign in across applications in Azure Active Directory B2C.

Is Azure AD going away? ›

Azure AD Powershell is planned to be deprecated on June 30, 2023. For more details on the deprecation plans, see the deprecation update.

How do I verify my domain in Azure B2C? ›

Verify the domain name with Azure AD
  1. Sign in with a user account that is a global administrator of your Azure AD directory.
  2. Open your directory and select the Domains tab.
  3. Select the domain name that you want to verify and select Verify on the command bar.
  4. Select Verify in the dialog box to complete the verification.
Feb 1, 2021

What authentication protocol does Azure AD B2C use? ›

Azure Active Directory B2C (Azure AD B2C) provides identity as a service for your apps by supporting two industry standard protocols: OpenID Connect and OAuth 2.0. The service is standards-compliant, but any two implementations of these protocols can have subtle differences.

Which three authentication methods can Azure AD users use? ›

Available verification methods
  • Microsoft Authenticator.
  • Authenticator Lite (in Outlook)
  • Windows Hello for Business.
  • FIDO2 security key.
  • OATH hardware token (preview)
  • OATH software token.
  • SMS.
  • Voice call.
Mar 14, 2023

How many characters should an authentication token be? ›

Default value: 20 characters. Minimum value: one character. Maximum value: 500 characters. If enabled, all the authorization grant tokens are revoked after an access token is validated.

What is the rate limit for Azure AD token? ›

A maximum of 500 transactions* per second per Application Proxy application. A maximum of 750 transactions per second for the Azure AD organization.

What is token in Active Directory? ›

The tokens are temporary keys that allow access to a system or network without actually providing your credentials. Delegate tokens are issued when a user logs on to a Windows Domain. This can be physically sitting in front of a windows box or remotely via Remote Desktop.

How long should refresh tokens last? ›

Refresh tokens have a longer lifetime than access tokens. The default lifetime for the refresh tokens is 24 hours for single page apps and 90 days for all other scenarios. Refresh tokens replace themselves with a fresh token upon every use.

How often do you need to refresh your access token? ›

By default, access tokens are valid for 60 days and programmatic refresh tokens are valid for a year. The member must reauthorize your application when refresh tokens expire.

What happens when access token expires? ›

When a token has expired or has been revoked, it can no longer be used to authenticate Git and API requests. It is not possible to restore an expired or revoked token, you or the application will need to create a new token.

What is the difference between API key and bearer token? ›

Bearer Tokens are used for authentication purposes, while API Keys are used for authorization purposes. Bearer Tokens authenticate the client and provide access to the API resources, while API Keys grant access to specific endpoints or actions.

What is the difference between JWT and refresh token? ›

The API returns a short-lived token (JWT), which expires in 15 minutes, and in HTTP cookies, the refresh token expires in 7 days. JWT is currently used for accessing secure ways on API, whereas a refresh token generates another new JWT access token when it expires or even before.

What is the difference between access token and session? ›

The main difference between the session and token authentication is that the authentication details are stored on the server side in session authentication and on the user side in token authentication. Token authentication is more secure than session authentication because a token cannot be tampered with.

How do I know if my Azure token is expired? ›

When you get an access token, part of the payload is an expires_in variable which tells you when the token will expire. You simply need to store that as a session variable, and check it before you make calls.

How do I change my Azure token expiration time? ›

Currently there is no way to change the expiration interval. These are the current expiration times. Source: and also my own experiences.

What should be the lifetime of access token? ›

Access token lifetime

By default, an access token for a custom API is valid for 86400 seconds (24 hours).

What are the 4 types of Azure AD? ›

Below we'll explain their differences in order to help you decide what you need.
  • Active Directory (AD) ...
  • Azure Active Directory (AAD) ...
  • Hybrid Azure AD (Hybrid AAD) ...
  • Azure Active Directory Domain Services (AAD DS)
Aug 25, 2019

Is Azure AD B2C free? ›

For example, for risk-based Conditional Access policies, you'll need to select the Azure AD B2C Premium P2 pricing tier for your tenant. Your first 50,000 MAUs per month are free for both Premium P1 and Premium P2 features, but the free tier doesn't apply to free trial, credit-based, or sponsorship subscriptions.

Does Azure B2C support SSO? ›

Single sign-on (SSO) adds security and convenience when users sign in across applications in Azure Active Directory B2C (Azure AD B2C). This article describes the single sign-on methods used in Azure AD B2C and helps you choose the most appropriate SSO method when configuring your policy.

How do I give access to Azure B2C tenant? ›

Sign in to the Azure portal. Make sure you're using the directory that contains your Azure AD B2C tenant. Select the Directories + subscriptions icon in the portal toolbar. On the Portal settings | Directories + subscriptions page, find your Azure AD B2C directory in the Directory name list, and then select Switch.

How do I get Azure B2C token postman? ›

Use Postman to get the Azure AD token
  1. Select form-data.
  2. Add grant_type key, and type client_credentials for the value.
  3. Add client_id key, and paste the value of client ID you noted down earlier.
  4. Add client_secret key, and paste the value of client secret you noted down earlier.
May 12, 2022

Where is Azure access token? ›

It represents the programmatic ID for Azure Databricks ( 2ff814a6-3304-4ab8-85cb-cd0e6f879c1d ) along with the default scope ( /. default , URL-encoded as %2f. default ). The Azure AD access token is in the access_token value within the output of the call.

What is Azure AD B2C authentication? ›

Azure AD B2C is a white-label authentication solution. You can customize the entire user experience with your brand so that it blends seamlessly with your web and mobile applications. Customize every page displayed by Azure AD B2C when your users sign-up, sign in, and modify their profile information.

Is Azure B2C a separate tenant? ›

Azure AD and Azure AD B2C are separate product offerings. To use Azure AD B2C features, create a separate Azure AD B2C tenant from your existing employee-based Azure AD tenant.

How to invite external Users to your tenant Azure Active Directory? ›

Add guest users to a group
  1. Sign in to the Azure portal as an Azure AD administrator.
  2. Search for and select Azure Active Directory from any page.
  3. Under Manage, select Groups.
  4. Select a group (or select New group to create a new one). ...
  5. Under Manage, select Members.
  6. Select Add members.
Apr 21, 2023

How do I give someone access to Azure Active Directory? ›

Azure portal
  1. Sign in to the Azure portal.
  2. Select Azure Active Directory > Roles and administrators to see the list of all available roles.
  3. Find the role you need. ...
  4. Select the role name to open the role. ...
  5. Select Add assignments and then select the users you want to assign to this role. ...
  6. Select Add to assign the role.
Mar 9, 2023

How do I get access token with client credentials in Postman? ›

Get the OAuth Access Token (Postman)
  1. In Postman, go to Authorization and select OAuth 2.0 as Type.
  2. Press button Get new Access Token.
  3. Enter any name for Token Name.
  4. In Auth URL enter the Authorization Endpoint URL you have copied before.
  5. In Access Token URL enter the Token Endpoint URL you have copied before.

How do I get bearer token from Azure AD REST API? ›

Create The Bearer Token
  1. Az-Login Command. Open elevated CMD, type az login and press Enter. ...
  2. Authenticate to Azure. Open in a web browser the page, enter the code ######## to authenticate the device on azure.
  3. Set The Azure Subscription. ...
  4. Create Azure Service Principal.
Dec 10, 2019

How do I validate my Azure AD security token? ›

The validate-azure-ad-token policy enforces the existence and validity of a JSON web token (JWT) that was provided by the Azure Active Directory service. The JWT can be extracted from a specified HTTP header, query parameter, or value provided using a policy expression or context variable.

How do I get an authorization token? ›

To create a new auth token:
  1. In the top-right corner of the Console, open the Profile menu and then click User Settings to view the details.
  2. On the Auth Tokens page, click Generate Token.
  3. Enter a friendly description for the auth token. ...
  4. Click Generate Token.
May 26, 2023

How do I validate an access token? ›

What to Check When Validating an Access Token
  1. Retrieve and parse your Okta JSON Web Keys (JWK), which should be checked periodically and cached by your application.
  2. Decode the access token, which is in JSON Web Token format.
  3. Verify the signature used to sign the access token.


1. Securing Your Web API with Azure AD B2C JWT Validation Policy: A Step-by-Step Guide | Azure | LSC
(Learn Smart Coding)
2. Azure AD B2C - Add Roles To Your App In Less Than 10 Minutes
(SSW TV | Videos for developers, by developers)
3. Using Azure B2C with An App
4. Application User Roles with Azure B2C
(The Pragmatic Programmer)
5. Azure Active Directory B2C (AAD B2C) for beginners
(Alexander Schmidt)
6. Azure B2C Access and Refresh Token
(ITLandy Tech)


Top Articles
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated: 08/02/2023

Views: 5593

Rating: 4.3 / 5 (64 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.