gpt4 book ai didi

azure - IdentityServer4 - 是否可以与外部提供商一起使用本地登录表单并且无需往返?

转载 作者:行者123 更新时间:2023-12-03 00:30:05 24 4
gpt4 key购买 nike

我正在尝试使用本地登录表单根据其外部提供商(Azure Active Directory)对用户凭据进行身份验证。

据我所知,您可以为每个客户端启用本地登录。这很有帮助,因为当设置为 true 时,我将获得本地登录表单,但我仍然不清楚如何为该外部提供商触发中间件。有没有办法将客户端凭据发送到外部提供商以接收 ID token ?我当前的代码重定向到 Microsoft 登录;然后回到我的身份服务器,然后是客户端应用程序。我希望用户通过身份服务器登录,但不让他们知道它实际上是针对 Azure 进行身份验证的。

这是我的启动:

        var schemeName = "Azure-AD";
var dataProtectionProvibder = app.ApplicationServices.GetRequiredService<IDataProtectionProvider>();
var distributedCache = app.ApplicationServices.GetRequiredService<IDistributedCache>();
var dataProtector = dataProtectionProvider.CreateProtector(
typeof(OpenIdConnectMiddleware).FullName,
typeof(string).FullName, schemeName,
"v1");
var dataFormat = new CachedPropertiesDataFormat(distributedCache, dataProtector);

///
/// Azure AD Configuration
///
var clientId = Configuration["AzureActiveDirectory:ClientId"];
var tenantId = Configuration["AzureActiveDirectory:TenantId"];
Redirect = Configuration["AzureActiveDirectory:TenantId"];

app.UseOpenIdConnectAuthentication(new OpenIdConnectOptions
{
AuthenticationScheme = schemeName,
DisplayName = "Azure-AD",
SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme,
ClientId = clientId,
Authority = $"https://login.microsoftonline.com/{tenantId}",
ResponseType = OpenIdConnectResponseType.IdToken,
StateDataFormat = dataFormat,
});

app.UseIdentity();
app.UseStaticFiles();
app.UseMvcWithDefaultRoute();

这是登录信息。

[HttpGet]
public async Task<IActionResult> ExternalLogin(string provider, string returnUrl)
{
var context = this.HttpContext.Authentication;
List<AuthenticationDescription> schemes = context.GetAuthenticationSchemes().ToList();

returnUrl = Url.Action("ExternalLoginCallback", new { returnUrl = returnUrl });

// start challenge and roundtrip the return URL
var props = new AuthenticationProperties
{
RedirectUri = returnUrl,
Items = { { "scheme", provider } }
};

//await HttpContext.Authentication.ChallengeAsync(provider, props);

return new ChallengeResult(provider, props);
}

最佳答案

在我看来,我们不应该直接将用户名/密码从其他 Idp 直接传递到 azure AD 进行身份验证作为安全实现。甚至 Azure AD 支持资源所有者密码凭据授予,它仅在 native 客户端中可用。我建议你保持正常的方式,不要混合它们。

关于azure - IdentityServer4 - 是否可以与外部提供商一起使用本地登录表单并且无需往返?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46459505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com