我正试图通过我的“网络8”批准“积极名录”用户进入下一个JS客户申请(使用msal-react),以便他们能够使用[Authorize]
终端。 然而,在将客户JWT送至我的APIC时,我收到了401份答复和我的APIC标志
I have registered both applications through Azure s App registrations. In my API registration, I have exposed my API to authorize my client app through a single scope, access_as_user
. I have confirmed this in my client s registration as a Delegated permission.
在我的“网络”中,Im打上了我的<代码>AzureAd配置,载于appdings.json
。
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"Domain": "qualified.domain.name",
"TenantId": "My-TENANT-ID",
"ClientId": "MY-CLIENT-ID",
"Scopes": "access_as_user",
"CallbackPath": "/signin-oidc"
},
I then add authentication to my services in my Program.cs
...
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(config.GetSection("AzureAd"));
...
app.UseAuthorization();
app.UseAuthentication();
...
最后,我设立了单一<代码>的简单控制器。
[Controller]
[Route("api")]
public class GeneralController : Controller
{
[Authorize]
[HttpGet("get")]
public Task<IActionResult> Test()
{
return Task.FromResult<IActionResult>(Ok());
}
}
In my client application, I retrieve my token after a user logs in with Azure AD.
const { instance, accounts } = useMsal();
...
instance.acquireTokenSilent({
scopes: [
"api://API-CLIENT-ID/access_as_user",
],
account: account,
})
I m 能够记录客户检索的标语,并在使用https://jwt.io/时, 我可以将《维也纳条约法公约》编码,以找到以下相关特性:
{
"aud": "API-CLIENT-ID",
"iss": "https://login.microsoftonline.com/CLIENT-TENANT-ID/v2.0",
"azp": "CLIENT-CLIENT-ID",
"name": "LOGGED-IN-USER-NAME",
"scp": "access_as_user",
"tid": "CLIENT-TENANT-ID",
"ver": "2.0"
}
However, when I include this token in a request s Authorization header to the general endpoint I set up, I receive a 401 response and the following logs from my API:
info: Microsoft.AspNetCore.Authorization.DefaultAuthorizationService[2]
Authorization failed. These requirements were not met:
DenyAnonymousAuthorizationRequirement: Requires an authenticated user.
info: Microsoft.AspNetCore.Authentication.JwtBearer.JwtBearerHandler[12]
AuthenticationScheme: Bearer was challenged.