I create an API and expecting access token from azure AD.
services.AddMvc(options => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); options.Filters.Add(new AuthorizeFilter(policy)); }).SetCompatibilityVersion(CompatibilityVersion.Version_3_0); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.Audience = Configuration["AzureAd:ClientId"]; options.Authority = $"{Configuration["AzureAd:Instance"]}{Configuration["AzureAd:TenantId"]}"; }); Then I created a SPA on react using MSAL but when I login the access token return from MSAL is not accepted on my API.
**function RequestProfileData() {
instance.acquireTokenSilent({ ...loginRequest, account: accounts[0] }).then((response) => { debugger; const api = axios.create({ baseURL: 'https://localhost:44312', headers: { authorization: `Bearer ${response.accessToken}` } }); api.get('/WeatherForecast').then(result => { debugger; console.log(result.data) }); })** https://stackoverflow.com/questions/66450649/azure-ad-authentication-token-not-authorize March 03, 2021 at 12:07PM
没有评论:
发表评论