我正在尝试使用Angular 4应用程序正确地使用Azure AD B2C进行隐式身份验证.我正在使用msal.js尝试让它工作.我已经检查了非常有限的官方示例代码,但它没有实际用途,因为它使用弹出窗口登录,我想进行重定向.
我现在拥有的是我在我的应用程序中注入的以下身份验证服务,该服务应该负责所有身份验证.
import { Injectable } from '@angular/core';
import * as Msal from 'msal';
@Injectable()
export class AuthenticationService {
private tenantConfig = {
tenant: "example.onmicrosoft.com",
clientID: 'redacted (guid of the client),
signUpSignInPolicy: "b2c_1_signup",
b2cScopes: ["https://example.onmicrosoft.com/demo/read", "openid"]
}
private authority = "https://login.microsoftonline.com/tfp/" + this.tenantConfig.tenant + "/" + this.tenantConfig.signUpSignInPolicy;
private clientApplication: Msal.UserAgentApplication;
constructor() {
this.clientApplication = new Msal.UserAgentApplication(this.tenantConfig.clientID, this.authority, this.authCallback);
}
public login(): void {
this.clientApplication.loginRedirect(this.tenantConfig.b2cScopes);
}
public logout(): void {
this.clientApplication.logout();
}
public isOnline(): boolean { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用OAUTH-KV Claims Resolver提取作为声明foo传递给 AAD B2C 自定义策略authorize端点的名为foo.
在foo ClaimType被定义为
<ClaimType Id="foo">
<DisplayName>Foo debug claim</DisplayName>
<DataType>string</DataType>
<UserInputType>TextBox</UserInputType>
</ClaimType>
Run Code Online (Sandbox Code Playgroud)
和TechnicalProfile作为
<TechnicalProfile Id="LocalAccount-Register">
<DisplayName>Register</DisplayName>
<Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.SelfAssertedAttributeProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
<Metadata>
<Item Key="ContentDefinitionReferenceId">api.localaccount.registration.prescribedfirm</Item>
<Item Key="IpAddressClaimReferenceId">IpAddress</Item>
<Item Key="language.button_continue">Create</Item>
</Metadata>
<CryptographicKeys>
<Key Id="issuer_secret" StorageReferenceId="B2C_1A_TokenSigningKeyContainer" />
</CryptographicKeys>
<InputClaims>
<InputClaim ClaimTypeReferenceId="foo" DefaultValue="{OAUTH-KV:foo}" />
</InputClaims>
<OutputClaims>
<OutputClaim ClaimTypeReferenceId="foo" Required="true" />
</OutputClaims>
<UseTechnicalProfileForSessionManagement ReferenceId="SM-AAD" />
</TechnicalProfile>
Run Code Online (Sandbox Code Playgroud)
但是,值foo显示为{OAUTH-KV:foo}而不是传递的实际值。
我相信我已按照文档中的说明进行操作。
我还需要做些什么来完成这项工作吗?
与索赔解析器相关的文档于 …
我试图了解如何使用 Azure AD B2C 密码重置。
似乎有多种方法可以处理密码重置。这些有什么区别?这些之间有价格差异吗?其中一些是 Azure AD 的功能,而一些是 Azure AD B2C 的功能?为什么下面的方法 3 似乎不起作用?
通过 Azure B2C 用户流(策略)。
通过 Azure Active Directory 自助服务密码重置。可通过https://passwordreset.microsoftonline.com访问。这允许用户通过存储在其个人资料中的任何电子邮件地址重置其密码。
用户配置文件上的重置密码按钮。这提供了一个临时密码,但是临时密码似乎不起作用。
我正在使用 Azure AD B2C 示例,出于测试目的,我使用了稍微修改过的 Single page app sample。我还创建了一个 Azure B2C 和一个测试 API(作为 Azure 函数)。测试 API 和单页应用程序已在 Azure B2C 中注册为适当的应用程序,并且设置工作正常。
该场景是用户登录 Azure B2C,获取令牌并使用令牌调用 Azure 函数。问题是登录页面在地址栏中带有 B2C Url 的单独窗口中打开。我想要的是将登录控件嵌入到单页应用程序中。
我浏览了文档,发现可以自定义登录页面(在用户流策略/页面布局中),但它似乎仍然是一个单独的页面,我不想要。另一个想法是让单页应用程序将登录请求作为 AJAX 请求发送到我自己的服务器,然后该服务器代表该用户执行登录,然后将令牌中继回单页应用程序。但这似乎很麻烦和不必要的间接,我想尽可能避免。
我创建了一个示例应用程序,用户可以在其中使用运行良好的 Azure B2C 进行身份验证。我取回令牌和 AuthenticationResult。两个都可以。但我想从令牌中取回 ClaimPrincipal 。为此,我已将 System.IdentityModel.Tokens.Jwt (5.4.0) nuget 包添加到项目中。
使用以下代码我尝试实现:
string Token = "eyJ0eXAiOiJKV1QiLCJhbGciO*****"; //long token
JwtSecurityTokenHandler jwt = new JwtSecurityTokenHandler();
var validateParams = new Microsoft.IdentityModel.Tokens.TokenValidationParameters()
{
ValidIssuer = Authority, //https://login.microsoftonline.com/tfp/MYTEANANTNAME.onmicrosoft.com/MYPOLICYNAME/v2.0/"
ValidAudience = clientId, //CLIENTID: Like: b430xxxx-xxxx-xxxx-xxxx-f5c33cxxxxxx
ValidateAudience = true,
ValidateLifetime = true,
ValidateIssuer = true,
};
SecurityToken secToken;
var claimPrincipal = jwt.ValidateToken(Token, validateParams , out secToken);
Run Code Online (Sandbox Code Playgroud)
但是,当 ValidateToken 被击中时,它会抛出以下异常:
IDX10501: Signature validation failed. Unable to match keys:
kid: '[PII is hidden]',
token: '[PII is hidden]'.
Run Code Online (Sandbox Code Playgroud)
你对我应该如何解决这个问题有什么建议吗?
在这种情况下,应用程序是 …
尝试实现以下场景:将 Azure B2c 和 azure AD 实现为身份提供者之一。实现它的唯一方法是使用自定义策略。我遵循了这些教程:https : //docs.microsoft.com/en-us/azure/active-directory-b2c/active-directory-b2c-get-started-custom#prerequisites https://docs.microsoft.com/ en-us/azure/active-directory-b2c/active-directory-b2c-setup-commonaad-custom#create-an-azure-ad-b2c-application 问题是当我尝试上传 TrustFrameworkExtensions.xml 时得到了我的信息租户
引用 ID 为“issuerUserId”的 ClaimType,但该策略及其任何基本策略均不包含此类元素。
在这里发现了类似的问题 https://github.com/MicrosoftDocs/azure-docs/issues/27602 并用 socialIdpUserId 替换 issuerUserId。似乎已解决,但在上传过程中出现了另一个问题:
使用 ID“CreateRandomUPNUserName”引用 ClaimsTransformation,但该策略及其任何基本策略均不包含此类元素。
从教程中获得了声明提供程序配置,现在我真的不知道如何修复它。在此先感谢您的帮助。
编辑
基于@CHris 解决方案,我使这些文件正确(上传期间没有错误),但解析返回令牌仍然存在一些问题。有没有人从第二个链接中启动并运行示例(Azure ad b2c 和在 multitentant azure ad 中注入的许多 azure ad)。
我们正在使用 Hasura 向消费者提供 GraphQL API。目前我们使用 Auth0 对用户进行身份验证,但我们希望迁移到 Azure AD B2C。
Hasura的 JWT 安全性要求是使用“ https://hasura.io/jwt/claims ”命名空间来提供自定义声明(例如 X-Hasura-Org-Id、X-Hasura-App-Id 等)。
我已经能够通过 AAD B2C 来:
string/值转换为 JSON 对象 和stringCollectionClaimsTransformation但是,我无法弄清楚如何在不转义内容的情况下让 JSON 对象出现在最终的 JWT 中 - 即作为字符串而不是对象输出。
AAD B2C 是否能够输出 JWT 中的嵌套对象?
这就是 Hasura 希望 JWT 命名空间的样子(注意对象https://hasura.io/jwt/claims)
{
"exp": 1588405829,
"nbf": 1588402229,
"ver": "1.0",
"iss": "https://<redacted>.b2clogin.com/<redacted>/v2.0/",
"sub": "<redacted>",
"aud": "<redacted>",
"acr": "b2c_1a_aaa_signupsignin",
"nonce": "defaultNonce",
"iat": 1588402229,
"auth_time": 1588402229,
"given_name": "Test", …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置 AD B2C,并遵循我在网上找到的各种教程。我正在测试用户流程。我可以成功登录,但是当我重定向到 时https://jwt.ms,它什么也没显示:
但是,我注意到我的 URL 与教程中显示的不同。它有一个code而不是id_token:
https://jwt.ms/?code=eyJraW...
Run Code Online (Sandbox Code Playgroud)
我一直试图找出导致 B2C 使用代码而不是 ID 令牌进行重定向的原因,但没有成功。谁能告诉我为什么会发生这种情况?
更新
好的,我现在明白是什么原因造成的,但不太明白我的设置与我在教程中看到的设置有何不同。我发现,如果我在应用程序注册中启用隐式授权,如下所示:
然后一切都会按预期进行。请注意,我必须启用两者。
我还注意到,当我测试用户流时,这些隐式授权的状态决定了它是否具有response_type=code或response_type=id_token位于授权 URL 中:
response_type除了更改隐式授予的状态之外,似乎没有其他方法可以在测试用户流程 UI 中设置所需的值。也许这是自教程制作以来 Azure 门户中行为的变化……?
我正在开发一个 Angular 10 应用程序,它利用 Azure B2C 进行策略和用户管理。我在 Azure Active Directory 中将我的应用注册设置为单页应用,但未选中隐式选项。我正在使用 msal.js 2.0@azure/msal-browser登录 B2C 并使用代码流检索 ID 和访问令牌。我设置了我的配置,创建了 msal 对象,定义了重定向承诺,然后使用适当的用户范围调用 loginRedirect。页面正确重定向。
但是,在我登录后,tokenResponse 返回为空。我曾尝试更改权限和范围,但它总是返回为空。如何让handleRedirectPromise返回有效的令牌响应?
这是我的代码:
private msalConfig: Msal.Configuration = {
auth: {
clientId: xxxx-xx-xx-xx-xxxxx,
authority: 'https://login.microsoftonline.com/common',
redirectUri: 'https://localhost:4200'
},
cache: {
cacheLocation: 'sessionStorage',
storeAuthStateInCookie: false
},
};
private loginRequest: Msal.RedirectRequest = {
scopes: ['user.read'],
};
const msalInstance = new Msal.PublicClientApplication(this.msalConfig);
msalInstance
.handleRedirectPromise()
.then((tokenResponse: Msal.AuthenticationResult) => {
let accountObj = null;
if (tokenResponse !== null) {
accountObj = tokenResponse.account; …Run Code Online (Sandbox Code Playgroud) 我正在尝试...@gmail.com通过 Graph API (C#)将带有电子邮件的用户添加到我的 B2C 目录。我得到这个作为回应:
userPrincipalName 属性的域部分无效。您必须在您的组织中使用经过验证的域名之一。
该系统需要允许任何电子邮件域的用户登录。用户需要登录网站,不能访问 Azure 门户。
有没有办法在不手动添加每个域的情况下完成此操作?
通过Graph API添加用户的代码:
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantId)
.WithClientSecret(clientSecret)
.Build();
var authProvider = new ClientCredentialProvider(confidentialClientApplication);
var graphClient = new GraphServiceClient(authProvider);
var user = new User
{
AccountEnabled = true,
DisplayName = emailAddress,
MailNickname = emailAddress.Split('@').FirstOrDefault(),
UserPrincipalName = emailAddress,
PasswordProfile = new PasswordProfile
{
ForceChangePasswordNextSignIn = true,
Password = tempPassword
}
};
Run Code Online (Sandbox Code Playgroud) azure-ad-b2c ×10
azure ×4
.net-core ×1
angular ×1
c# ×1
hasura ×1
identity-experience-framework ×1
jwt ×1
login ×1
msal.js ×1
typescript ×1