使用 AddAzureADB2C 时如何挂接到 AuthorizationCodeReceived?
How to hook into AuthorizationCodeReceived when using AddAzureADB2C?
我创建了一个简单的 Blazor 服务器应用程序,它链接到 Azure B2C 目录以进行授权。
一切正常,但我需要向令牌添加额外的角色声明。研究指出 which refers to adding the claims during the AuthorizationCodeReceived
notification(Example here).
我明白我需要做什么,但示例使用的是 OpenIdConnectAuthentication(来自 Microsoft.Owin.Security.OpenIdConnect
)而不是 Blazor 服务器的 Microsoft.AspNetCore.Authentication.AzureADB2C.UI
.
收到令牌后,我如何仍然可以访问和修改令牌中的声明? Microsoft.AspNetCore.Authentication.AzureADB2C.UI
支持这样的东西还是应该切换到 OpenId?
下面是包含在基本 Blazor 服务器应用程序中的样板,但 AzureADB2COptions
都只是字符串配置值。
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
services.AddRazorPages();
services.AddServerSideBlazor().AddCircuitOptions(o =>
{
if (_environment.IsDevelopment()) //only add details when debugging
{
o.DetailedErrors = true;
}
});
// remaining service configuration
}
您可以尝试在 AddAzureADB2C
之后覆盖特定架构,然后注册您的事件,例如:
services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.OpenIdScheme, options =>
{
options.ResponseType = "code";
options.Events = new OpenIdConnectEvents
{
OnAuthorizationCodeReceived= async ctx =>
{
.....
},
};
});
使用 options.ResponseType = "code"
对访问令牌交换进行分类,否则 OnAuthorizationCodeReceived
不会触发,您可以按照 here 中的代码示例,该代码示例不直接使用库 ,但具有与 Microsoft.AspNetCore.Authentication.AzureADB2C.UI1
相同的逻辑
我创建了一个简单的 Blazor 服务器应用程序,它链接到 Azure B2C 目录以进行授权。
一切正常,但我需要向令牌添加额外的角色声明。研究指出 AuthorizationCodeReceived
notification(Example here).
我明白我需要做什么,但示例使用的是 OpenIdConnectAuthentication(来自 Microsoft.Owin.Security.OpenIdConnect
)而不是 Blazor 服务器的 Microsoft.AspNetCore.Authentication.AzureADB2C.UI
.
收到令牌后,我如何仍然可以访问和修改令牌中的声明? Microsoft.AspNetCore.Authentication.AzureADB2C.UI
支持这样的东西还是应该切换到 OpenId?
下面是包含在基本 Blazor 服务器应用程序中的样板,但 AzureADB2COptions
都只是字符串配置值。
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication(AzureADB2CDefaults.AuthenticationScheme)
.AddAzureADB2C(options => Configuration.Bind("AzureAdB2C", options));
services.AddRazorPages();
services.AddServerSideBlazor().AddCircuitOptions(o =>
{
if (_environment.IsDevelopment()) //only add details when debugging
{
o.DetailedErrors = true;
}
});
// remaining service configuration
}
您可以尝试在 AddAzureADB2C
之后覆盖特定架构,然后注册您的事件,例如:
services.Configure<OpenIdConnectOptions>(AzureADB2CDefaults.OpenIdScheme, options =>
{
options.ResponseType = "code";
options.Events = new OpenIdConnectEvents
{
OnAuthorizationCodeReceived= async ctx =>
{
.....
},
};
});
使用 options.ResponseType = "code"
对访问令牌交换进行分类,否则 OnAuthorizationCodeReceived
不会触发,您可以按照 here 中的代码示例,该代码示例不直接使用库 ,但具有与 Microsoft.AspNetCore.Authentication.AzureADB2C.UI1