Make request to verify if the azure b2c token is still validate

emmanuel hdz 80 Reputation points
2024-01-16T22:48:18.8133333+00:00

Hi, Currently, I have my Flutter app with a custom policy (Azure B2C). When the user successfully authenticates, the policy returns a token, which is then stored in the app user preferences. I would like to know how it is possible to fetch the token from somewhere (I presume Azure server) to verify if the saved token in the app is still valid. Thanks in advance.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments

Answer accepted by question author
Akshay Kaushik 18,041 Reputation points Microsoft Employee Moderator
2024-01-17T08:49:37.1066667+00:00

@emmanuel hdz
To extract the token issued to a Flutter app, you try using the flutter_appauth package. This package provides a set of Flutter widgets and functions that make it easy to implement the OAuth 2.0 and OpenID Connect protocols in your app.

import 'package:flutter_appauth/flutter_appauth.dart';

final FlutterAppAuth appAuth = FlutterAppAuth();

final AuthorizationTokenResponse result =
    await appAuth.authorizeAndExchangeCode(
  AuthorizationTokenRequest(
    '<client_id>',
    '<redirect_uri>',
    issuer: '<authority>',
    scopes: ['openid', 'profile', 'email'],
  ),
);

final String accessToken = result.accessToken;


The authorizeAndExchangeCode() method is used to obtain an access token from Azure AD B2C. The method takes an AuthorizationTokenRequest object that specifies the client ID, redirect URI, authority, and scopes for the request. The method returns an AuthorizationTokenResponse object that contains the access token. You can extract the access token from the AuthorizationTokenResponse object by accessing the accessToken property. Another conceptual workaround could be referred here.

---Please "Accept the answer (Yes)" and "share your feedback ". This will help us and others in the community as well. Thanks, Akshay Kaushik

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.