Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

395
Views
Unauthorized when requesting a token from Azure App Service

I'm creating a simple web app that needs to call an Azure Function.

I've registered 2 apps in my Azure AD: one for my single page react application and another for my Azure Function.

two app registrations

The app for my azure function has an API exposed on it and a scope configured called CallApi.

api and scope

The app itself has authentication configured on it (easy auth), and the client id matches the API app registration within AAD: auth on app

The app for my SPA has permission to request this scope and this is granted by default for all users.

permissions for client

I am able to successfully log users into my SPA and get an access token. I'm doing this with the use of the @azure/msal-browser and @azure/msal-react npm libraries, specifically:

<MsalAuthenticationTemplate interactionType={InteractionType.Redirect} authenticationRequest={{scopes: ["User.Read", "api://<redacted>/CallApi"]}} >

However, the access token that is returned only has these scopes: ['openid', 'profile', 'User.Read', 'email'] and not api://<redacted>/CallApi. So when I try to exchange my access token for a token by sending a POST request to https://<app_name>.azurewebsites.net/.auth/login/aad it returns an unauthorized message.

How can I ensure that the CallApi scope is allow by my app?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

So when I try to exchange my access token for a token by sending a POST request to https://<app_name>.azurewebsites.net/.auth/login/aad it returns an unauthorized message.

Please ensure that the URL is correct as it should be in the format of <app-url>/.auth/login/aad/callback and note that the parameters are in the body of the HTTP POST request.

However, the access token that is returned only has these scopes: ['openid', 'profile', 'User.Read', 'email']

openid

If an app performs sign-in by using OpenID Connect, then it must request the openid scope. That is to say, the openid scope displays on the work account consent page as the “Sign you in” permission.

email

The email scope can work with the openid scope. As it gives the app access to the user’s primary email address in the form of the email claim. Where, the email claim is included in a token only if an email address is associated with the user account, which isn’t always the case.

profile

The profile scope can also work with the openid scope. This gives the app access to a substantial amount of information about the user. The information that it has access includes, the user’s given name, surname, preferred username, and object ID.

In the Microsoft ecosystem there are some high-privilege permissions that can be set to admin-restricted. This include:

  • Firstly, read all user’s full profiles by using User.Read.All
  • Secondly, write data to an organization’s directory by using Directory.ReadWrite.All
  • Lastly, read all groups in an organization’s directory by using Groups.Read.All

Please refer this article for an example regarding the POST request regarding the Call API Scope.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!