在Azure B2C中,我曾经通过使用JWT 检索Azure AD组信息,在我的JWT令牌中获得"组"声明:
"groupMembershipClaims":"SecurityGroup",
这在过去一直运作良好(大约一个月前,我相信......)但它已不复存在了.详见下文......
按照上面已知的好食谱.
不幸的是,这不再起作用 - 当此客户端尝试使用B2C验证我时出现以下错误:
AADB2C90068:提供的ID为"032fe196-e17d-4287-9cfd-25386d49c0d5"的应用程序对此服务无效.请使用通过B2C门户创建的应用程序,然后重试"
好吧,公平 - 他们正在把我们带到新门户网站.
使用新的Portal,按照好的旧配方.
但这也不起作用 - 当我到达"下载清单"部分时,我找不到任何方法来访问清单(并且谷歌搜索告诉我它可能已经好了......).
有点绝望,我尝试混合计划A和B:使用新的Portal注册应用程序,然后使用旧的Azure Manager更改清单.
但没有运气 - 当我尝试上传清单时,它会失败并显示消息
ParameterValidationException =提供的参数无效; BadRequestException =此版本不允许对聚合应用程序进行更新.
只需放弃"组"声明 - 相反,每当我需要组信息时,只需使用Graph API查询B2C服务器.
我真的,真的不想这样做 - 它会破坏访问令牌的自包含性,并使系统非常"健谈".
但是我把它作为Z计划包括在内,只是说:是的,我知道选项存在,不,我没有尝试过 - 而且我不愿意.
如何在我的JWT令牌中获得"团体"声明这些天?
我有一个与Azure AD B2C连接的Asp.NET MVC应用程序.
在管理员设置中,我创建了一个管理员组:
在我的代码中我想使用 [Authorize(Roles = "Administrator")]
使用常规的Azure Active Directory,它很容易添加(只需3行代码).但对于Azure AD B2C,我找不到任何有用的教程或示例.也许你可以告诉我我需要修改什么.
这是我的Startup.Auth.cs的ConfigureAuth方法
public void ConfigureAuth(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseCookieAuthentication(new CookieAuthenticationOptions());
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
// Generate the metadata address using the tenant and policy information
MetadataAddress = String.Format(AadInstance, Tenant, DefaultPolicy),
// These are standard OpenID Connect parameters, with values pulled from web.config
ClientId = ClientId,
RedirectUri = RedirectUri,
PostLogoutRedirectUri = RedirectUri,
// Specify the callbacks for each type of notifications
Notifications = new OpenIdConnectAuthenticationNotifications
{
RedirectToIdentityProvider = …Run Code Online (Sandbox Code Playgroud) 我想向使用 Azure AD B2C 以 Asp.Net Core 编写的 Web API 添加授权。我已经有了身份验证部分,现在我想在我的应用程序中添加“角色”,比如“管理员”,并且可能在未来添加更具体的角色。
我已经看到 Azure AD 添加“应用程序角色”的示例,但找不到任何适用于 AD B2C 的内容。Azure 门户中似乎没有任何内容,文档中也没有任何内容。
是否可以将自定义应用程序角色添加到 Azure AD B2C?
我正在创建一个使用 azure AD B2C 进行身份验证的 asp net core 2 web api。我想使用 AD B2C 组将某些控制器的使用限制为管理员成员。
我已经明白,目前实现这一目标的唯一方法是访问图形 API 并将一些角色声明添加到用户的声明中。
但是我在启动时查询图形 api 时遇到了麻烦。
我的ConfigureService方法是这样的:
services.AddAuthentication(sharedOptions =>
{
sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
sharedOptions.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme;
})
.AddAzureAdB2C(options => Configuration.Bind("AzureAdB2C", options))
.AddJwtBearer(options => {
options.Authority = string.Format("https://login.microsoftonline.com/tfp/{0}/{1}/v2.0/", "b2ctenant.onmicrosoft.com", "B2C_1_DefaultSignUpIn");
options.Audience = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx";
options.Events = new JwtBearerEvents
{
OnTokenValidated = OnAuthorizationCodeReceived,
};
})
.AddCookie(options =>
{
options.LoginPath = "/Account/SignIn";
options.LogoutPath = "/Account/SignOut";
options.Cookie.SecurePolicy = CookieSecurePolicy.Always;
options.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = OnRedirectToLogin
};
}); …Run Code Online (Sandbox Code Playgroud) azure-ad-graph-api azure-ad-b2c asp.net-core-webapi asp.net-core-2.0
我们正在尝试将 Azure AD B2C 集成到 SPA 中。我们希望在票证中包含角色,以便我们可以在 api 中使用 AuthorizeRoles 和 IsInRole。我们看了几个例子。
第一个示例不是 SPA,也不包含角色。根据以下链接,不支持使用 Azure AD B2C 在票证中包含成员资格和组。
上面建议的解决方法似乎是使用下面的“OnAuthorizationCodeReceived”事件将您自己的角色声明注入/添加到票证。
我们遇到的问题是我们使用的是 SPA,因此我们需要遵循示例 2,我们还需要能够将我们自己的托管角色添加到不支持的功能的票证中,但微软表示有一个解决方法显示。但是,该解决方法不适用于示例 2 中的 MSAL.js。
我们如何使用 MSAL.js 库将我们自己的托管角色包含到票证中,以便我们可以将 Azure AD B2C 集成到我们的 SPA 中,从而使我们能够在 api 中使用 AuthorizeRoles 和 IsInRole?
roles azure single-page-application azure-ad-b2c azure-ad-msal
我尝试使用当前推荐的授权代码流和 PKCE 从 Active Directory 收集访问令牌。客户端将是一个公共 Angular SPA,这是选择流程的原因。
收集 openid-configuration 表单 AD 以及用户的授权代码效果很好。但是我无法从以下端点请求访问令牌:
https://login.microsoftonline.com/{tenantId}/oauth2/token.
Run Code Online (Sandbox Code Playgroud)
我试图在 Postman 中重建请求:
POST /7e8c2868-7490-4dd7-82b7-f5ec29222d30/oauth2/token HTTP/1.1
Host: login.microsoftonline.com
Accept: application/json, text/plain, */*
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
grant_type=authorization_code
code=...
code_verifier=...
client_id=...
redirect_uri=...
Run Code Online (Sandbox Code Playgroud)
...并最终得到以下消息:
{
"error": "invalid_client",
"error_description": "AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'.\r\nTrace ID: ed0413ad-89f1-4a2b-8d68-e23498701800\r\nCorrelation ID: deb53b0d-5398-4f72-a9a5-6c0863547b99\r\nTimestamp: 2020-03-06 09:30:36Z",
"error_codes": [
7000218
],
"timestamp": "2020-03-06 09:30:36Z",
"trace_id": "ed0413ad-89f1-4a2b-8d68-e23498701800",
"correlation_id": "deb53b0d-5398-4f72-a9a5-6c0863547b99",
"error_uri": "https://login.microsoftonline.com/error?code=7000218"
}
Run Code Online (Sandbox Code Playgroud)
这看起来很奇怪,因为带有 PKCE 的身份验证流程的官方规范不需要 client_secret 或 client_assertion。这仅对默认身份验证流程是必需的。
AD 实现有问题还是我配置错误? …