locked
Azure AD Angular client is get not Authorized error even with appended access token RRS feed

  • Question

  • User956626884 posted

    Hi,

    I have an angular client which was able to authenticate and received a token from Azure AD. I added the token to the header and called the WebAPI. I constantly get the following message

    "Authorization has been denied for this request."

    I get this error with the Angular and Google Postman.

    From the angular, I added the token to the header request as the following

    this.http.get<T>(endpointUrl, this.getHeaderWithToken());


    from the getHeaderWithToken call, I do see the token is added to the header

    let token = this.authService.getAccessToken();
    let headers = new HttpHeaders({
    'Authorization': 'Bearer ' + token,


    I also used Postman, Clicked on Authorization tab, pasted the token in the Token field.

    Both returned a failed message.

    On the webAPI code

    I created a startup file inside the App_Start folder, I verified that the following code is called

    public void ConfigureAuth(IAppBuilder app)
    {
    var azureADBearerAuthOptions = new WindowsAzureActiveDirectoryBearerAuthenticationOptions
    {
    Tenant = ConfigurationManager.AppSettings["TenantId"]
    };

    azureADBearerAuthOptions.TokenValidationParameters =
    new TokenValidationParameters()
    {
    ValidAudience = ConfigurationManager.AppSettings["Audience"]
    };

    app.UseWindowsAzureActiveDirectoryBearerAuthentication(azureADBearerAuthOptions);
    }

    It is registered on Azure AD.

    This test should work with Google Postman, right?

    I am trying to call this test message to see if my request is working

    [Route("test")]
    [HttpGet]
    [Authorize]
    public string Test()
    {
    return "Success";

    }


    The request does break on the constructor but does not allow to call this test method. Yes, it works without the [Authorize].

    Any help is appreciated. Thanks.

    Monday, July 22, 2019 3:17 PM

All replies

  • User1724605321 posted

    Hi comicrage ,

    Could you please show that how do you get the access token for your web api ?

    Best Regards,

    Nan Yu

    Tuesday, July 23, 2019 5:33 AM