Retrieve Access Token within a AAD secured Azure Web App

前端 未结 3 508
半阙折子戏
半阙折子戏 2021-01-13 18:45

I have an Angular4 Application hosted in an Azure Web App and a .NET core Web API hosted in an Azure API App.

The API is secured with Azure Active Directory. Curren

3条回答
  •  星月不相逢
    2021-01-13 19:07

    The AppServiceAuthSession is cookie which is different than a token. In this scenario, you need to modify the config of Azure app to make it acquire the access_token for the web API.

    We can use the Resource Explore to modify the settings like below:

    1 . locate the angular web app

    2 . locate the config->authsettings(resource is the clientId of Azure app which used to protect your apps)

    "additionalLoginParams": [
      "response_type=code id_token",
      "resource=3fa9607b-63cc-4050-82b7-91e44ff1df38"
    ],
    

    3. config the redirect_uri for Azure app like below: https://appfei.azurewebsites.net/.auth/login/aad/callback

    Then after you login in the angular app, you can get the access_token via the endpoint: https://appfei.azurewebsites.net/.auth/me

    Then we need to protect the web API using the Advanced Azure Active Settings like figure below to enable the access_token could call the web API:

提交回复
热议问题