Я мигрирую из ADAL в MSAL.
Я добавил приведенную ниже конфигурацию в angular 8:
MsalModule.forRoot({
auth: {
clientId: "xxxxx",
authority: "https://login.microsoftonline.com/tenant",
validateAuthority: true,
redirectUri: window.location.href,
postLogoutRedirectUri: "http://localhost:4200/",
navigateToLoginRequestUrl: true
},
cache: {
cacheLocation: 'localStorage',
storeAuthStateInCookie: isIE, // set to true for IE 11
},
},
{
popUp: false,
consentScopes: ['Directory.AccessAsUser.All',
'user.read',
'openid',
'profile',
'User.ReadWrite',
'User.ReadBasic.All',
'User.Read.All',
'Group.Read.All',
'Directory.AccessAsUser.All'
],
unprotectedResources: ['https://www.microsoft.com/en-us/'],
protectedResourceMap,
extraQueryParameters: {}
}),
Также я пытаюсь выполнить проверку путем получения токена
const loginRequest = {
scopes: ['user.read','openid', 'profile'],
};
this.authService.acquireTokenSilent(loginRequest);
this.broadcastService.subscribe("msal:acquireTokenFailure", (payload) => {
console.info("acquire token failure " + JSON.stringify(payload));
});
this.broadcastService.subscribe("msal:acquireTokenSuccess", (payload) => {
console.info("acquire token success " + JSON.stringify(payload));
});
In. net сторона, которую я написал следующий код:
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options =>
{
AuthenticationOptions authSettings = Configuration.GetSection("AzureAd").Get<AuthenticationOptions>();
options.Authority = authSettings.Authority;
options.SaveToken = true;
options.Events = new JwtBearerEvents
{
OnTokenValidated = context =>
{
// Add the access_token as a claim, as we may actually need it
if (context.SecurityToken is JwtSecurityToken accessToken)
{
if (context.Principal.Identity is ClaimsIdentity identity)
{
identity.AddClaim(new Claim("access_token", accessToken.RawData));
}
}
return Task.CompletedTask;
},
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
// If the request is for our hub...
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
((path.StartsWithSegments(SignalRHub) || path.StartsWithSegments(QuillHub))))
{
// Read the token out of the query string
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
options.TokenValidationParameters = new TokenValidationParameters
{
//Both the client id and app id URI of this API should be valid audiences
ValidAudiences = new List<string> { authSettings.ClientId },
};
});
Но когда я пытаюсь получить токен, я получаю токен успеха, но в API, я получаю ошибку говоря, что эмитент 'https://login.microsoftonline.com/tenantid/v2.0' недействителен
Что я делаю не так?