Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm building a SPA application with angular 10. The App should connect to an Azure secured web api to get the data.

When I connect to the web api, I get this error

"Microsoft.Identity.Web.MicrosoftIdentityWebChallengeUserException: IDW10502: An MsalUiRequiredException was thrown due to a challenge for the user. See https://aka.ms/ms-id-web/ca_incremental-consent. ---> MSAL.NetCore.4.29.0.0.MsalUiRequiredException: ErrorCode: user_null

I can connect to my web api from another ASP.net web app but not from my Angular App. I think the problem is that azure configurations are different in both Angular and the web api and my angular app generates a different token than the one the api is excepting.

Any suggestions to solve that?

What I have tried:

This is my angular azure configuration

TypeScript
export const environment = {
  apiURL:'https://localhost:44382',
  clientId: 'my-client-id',
  authority: 'https://login.microsoftonline.com/tenant-id',
  redirectUri: 'authorize/signin',
  scopes: ['User.Read']
};


AppComponent

TypeScript
import { Component } from '@angular/core';
import { MsalProvider, Providers } from '@microsoft/mgt';
import { environment } from 'src/environments/environment';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
  ngOnInit(){
     Providers.globalProvider = new MsalProvider({
        clientId: environment.clientId,
        authority: environment.authority,
        redirectUri: environment.redirectUri,
        scopes: environment.scopes,      
           });       
    Providers.globalProvider.getAccessToken().then(accessToken=>{console.log(accessToken);});

  }
}


This is my Azure configuration in the web api

ASP.NET
"AzureAd": {
   "ClientId": "my-client-id",
   "Scopes": [ "User.Read" ],
   "ClientSecret": "client-secret",
   "Instance": "https://login.microsoftonline.com/",
   "TenantId": "tenant-id"
 }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900