使用外部租户Azure active directory登录
当外部azure用户尝试登录时,他们会获得:使用外部租户Azure active directory登录,azure,azure-active-directory,passport.js,Azure,Azure Active Directory,Passport.js,当外部azure用户尝试登录时,他们会获得: TokenError: AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token. 当来自与azure ad客户端相同的组织的用户驻留在其中时,该客户端将工作 在Azure授权设置“受支持的帐户类型”中,我可以切换选项:“任何组织中的帐户” 后端代码:
TokenError: AADSTS54005: OAuth2 Authorization code was already redeemed, please retry with a new valid code or use an existing refresh token.
当来自与azure ad客户端相同的组织的用户驻留在其中时,该客户端将工作
在Azure授权设置“受支持的帐户类型”中,我可以切换选项:“任何组织中的帐户”
后端代码:
passport.use(
new AzureAdOAuth2Strategy(
{
clientID: process.env.AZURE_CLIENT_ID,
clientSecret: process.env.AZURE_CLIENT_SECRET,
callbackURL: `${getBaseUrl()}/api/login/callback`,
tenant: 'common',
useCommonEndpoint: true
}, async (accessToken, refresh_token, params, profile, done) => {...
因此,tenant
设置为“common”
以启用多租户组织,Azure中的设置设置为允许多租户
有什么不对劲 奇怪的问题。我有一位客户有你提到的类似症状 最后,在重现了我的问题之后:在Azure登录重定向后,webrequest登录到DNN页面上,创建了两个“ExchangeCodeForToken”请求(第一个请求被接受,但第二个请求无效,因为根据10月10日的更新,代码已经处理) 我发现了一个更新的发布包,它避免了第二次调用,这是从《泰晤士报》一开始就有的 新版本v3.0.1如下所示。你能再核对一下吗?我已经安装在我的客户网站上,现在工作正常
https://github.com/davidjrh/dnn.azureadprovider/releases/tag/v3.0.1
由于Azure AD中最近的更新,这种行为是意料之中的。从10月10日起,Azure AD将不再接受授权码来发行已经使用过的代币。要修复此错误,请尝试更改代码以请求一个刷新令牌,该令牌将传递给其他资源或由其他资源使用,因为刷新令牌仍然可以重用。我也在这篇文章中链接了官方公告,供您参考
app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
ClientId = ClientId,
ClientSecret = ClientSecret,
Authority = Authority,
CallbackPath = CallbackPath,
ResponseType = OpenIdConnectResponseType.CodeIdToken,
Events = new OpenIdConnectEvents
{
OnAuthorizationCodeReceived = async context =>
{
var authorizationCode = context.ProtocolMessage.Code;
ClientCredential clientCredentials = new ClientCredential(ClientId, ClientSecret);
AuthenticationContext authorizationContext = new AuthenticationContext(Authority);
AuthenticationResult authorizationResult = await authorizationContext.AcquireTokenByAuthorizationCodeAsync(authorizationCode, new Uri(context.Properties.Items[OpenIdConnectDefaults.RedirectUriForCodePropertiesKey]), clientCredentials, GraphResourceId);
var accessToken = authorizationResult.AccessToken;
GraphServiceClient graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
{
requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);
}));
.....
.....
.....
}
}
您是否以匿名模式再次尝试过?顺便说一下,如果启用useCommonEndpoint,则不需要租户参数
我可以使用下面返回的代码与外部租户用户一起登录。您能在这里粘贴登录代码吗?将来宾用户添加到目录中 以分配了有限管理员目录角色或来宾邀请者角色的用户身份登录Azure门户。 在导航窗格中,选择Azure Active Directory。 在管理下,选择用户。 选择新来宾用户。。。
在用户名下,输入外部用户的电子邮件地址。这是某个.NET软件包吗?我用的是带护照的NodeJs。