AADSTS65001 Failed to acquire token silentely when trying to get Azure Devops scopes access

Jonathan MARTIN--MAESTRE 0 Reputation points
2024-07-16T14:38:01.87+00:00

I have a JS Application that is an SPA registred in azure with the following authorized APIs
User's image

As you can see, none of them require Administrator consent.

When calling for silent token, I am using the following

export const apiRequest = {
    scopes: [
        'user_impersonation',
        'vso.tokenadministration',
        'vso.tokens',
        'vso.work',
        'vso.work_full',
        'User.Read',
        'User.ReadBasic.All'
    ],
    forceRefresh: false
};

# Component :
...
const { instance } = useMsal();
useEffect(() => {
        const fetchToken = async () => {
            try {
                const response = await instance.acquireTokenSilent(apiRequest);
                setAccessToken(response.accessToken);
            } catch (error) {
                console.error('Failed to acquire token silently', error);
            }
        };

        fetchToken();
    }, [instance]);
...

I use the following react libraries and versions :

"@azure/msal-browser": "^3.11.1",
"@azure/msal-react": "^2.0.14"        

Login works well and redirects me into my application, but when I am trying to fetchToken to call for Azure Devops, I end up with the following error :

Failed to acquire token silently InteractionRequiredAuthError: invalid_grant: AADSTS65001: The user or administrator has not consented to use the application with ID '[id]' named '[name]'. Send an interactive authorization request for this user and resource. Trace ID: [traceId] Correlation ID: [CorrelationId] ...

For obvious reasons, I don't want to ask or be granted unnecessary administrator consent to my application if it is not required which I get no indication that it is, what could I do to understand where is something wrong ? Thanks in advance

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
2,160 questions
JavaScript API
JavaScript API
An Office service that supports add-ins to interact with objects in Office client applications.
994 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,064 questions
0 comments No comments
{count} votes

Your answer

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