0

I am using the aad_oauth library in my Flutter app for Microsoft authentication. The authentication flow seems to work, but when I attempt to retrieve the refresh token, it returns null. Also I'm getting the access token and its expiry time

Here’s the relevant part of my code:

 Future<Either<Failure, String>> msAADRefresh() async {
try {
  final AadOAuth oauth = config;
 final refreshToken = await oauth.refreshToken();
  return refreshToken.fold((failure) => left(Failure()),
      (token) => right(token.refreshToken.toString()));
} catch (e) {
  return left(Failure(e.toString()));
}

Note: I have attached all my config in config variable. I'm able to logged in but not getting the refresh token.

3
  • Make sure to include offline_access in the scopes when initializing the AadOAuth instance to get the refresh token. Commented Jan 27 at 6:54
  • 1
    @DasariKamali could u please provide example?? mine is like this scope = 'api://example.app.com/tenant_id/.default' Commented Jan 27 at 7:11
  • 1
    @DasariKamali I have modified my url bit scopes ="offline_access api://example.app.com/tenant_id/.default' it worked. thanks Commented Jan 27 at 17:36

1 Answer 1

1

When attempting to retrieve the refresh token using the aad_oauth library in a Flutter app for Microsoft authentication, it returns null because the refresh token requires the offline_access scope to be included.

In Azure Portal, under App Registration-> API permissions -> Add permisson -> offline_access as shown below.

enter image description here

Make sure to add offline_access in the scopes list in your code as shown below.

scopes ="offline_access api://example.app.com/tenant_id/.default"

Output :

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.