Share via

Trouble in Forcing Consent Prompt and Scopes Declined Error with MSAL on Android

Terence Sajere 0 Reputation points
2023-06-19T10:33:40.4666667+00:00

Dear Microsoft Support,

I am developing an Android application that uses the Microsoft Identity Platform for authentication. I am using the MSAL library for this.

However, I have been encountering issues with getting the application to prompt for user consent, despite setting the Prompt parameter to "CONSENT" as recommended in the MSAL documentation. I am expecting to see a consent prompt screen after the user signs in, but this screen does not appear.

Additionally, even after following the MSAL documentation and setting the correct scopes, I am getting an error message stating, "some or all requested scopes have been declined by the server" when trying to sign in. Interestingly, when I remove the "offline_access" scope from the list, I am able to sign in without the error. However, I need the "offline_access" scope for my application.
Here's a simplified code snippet illustrating how I'm initiating the sign-in process:

val scopes = listOf(     "openid",     "User.Read",     "Mail.Send",     "Mail.ReadWrite",     "offline_access" )  
val parameters = AcquireTokenParameters.Builder()     .startAuthorizationFromActivity(this)     .withScopes(scopes)     .withLoginHint(userEmail)  // Pass the email as the login hint     .withPrompt(Prompt.CONSENT)  // Force consent prompt     .withCallback(object : AuthenticationCallback {         override fun onSuccess(authenticationResult: IAuthenticationResult) {             // Handle success         }         override fun onError(exception: MsalException) {             // Handle error         }         override fun onCancel() {             // Handle cancellation         }     })     .build()  myPublicClientApplication.acquireToken(parameters)

I have ensured that the requested scopes match the permissions that I've set in my app registration on the Azure portal.

Could you please help me understand why the consent prompt is not showing and why I am getting a scopes declined error when the "offline_access" scope is included?

Your help would be greatly appreciated.

Best Regards,

Terence.

Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph

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.