Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

405
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda