首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >跳过IdentityServer3登录屏幕

跳过IdentityServer3登录屏幕
EN

Stack Overflow用户
提问于 2015-04-29 12:37:34
回答 3查看 7.6K关注 0票数 16

我们已经将客户端应用程序配置为通过IdentityServer3连接协议使用OpenID身份验证(使用OIDC中间件的是ASP.NET MVC应用程序)。

IdentityServer3本身被配置为同时使用本地登录和外部登录(例如Azure)。

在常规流程中,一旦应用程序需要对用户进行身份验证,它就会将用户重定向到IdentityServer3登录屏幕--这很好。但在某些情况下,在每次请求的基础上,我想绕过登录屏幕,让IdentityServer3知道用户希望立即使用特定的外部身份提供者登录。

可以这样做吗?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2015-05-02 06:55:18

刚刚在IdentityServer3 3的授权/身份验证终结点文档中找到了解决方案!

acr_values (可选)允许将其他身份验证相关信息传递给用户服务--还有一些具有特殊意义的值:idp:name_of_idp绕过登录/主域屏幕,将用户直接转发给选定的身份提供者(如果允许每个客户端配置的话),tenant:name_of_tenant可用于将租户名称传递给用户服务。

如何使用OWIN OpenID连接中间件:https://katanaproject.codeplex.com/workitem/325传递附加参数

以下是授权请求的示例:

票数 19
EN

Stack Overflow用户

发布于 2016-12-02 18:26:09

我知道这是旧的,但我认为如果有人想要自动重定向到外部登录,我仍然会把它放在这里帮助他们:

代码语言:javascript
复制
public override Task PreAuthenticateAsync(PreAuthenticationContext context)
{
    context.SignInMessage.IdP = "windows";
    return base.PreAuthenticateAsync(context);  
}

您基本上可以重写PreAuthenticateAsync on UserServiceBase,并将context.SignInMessage上的属性IdP更改为已在启动过程中设置的外部提供程序名称。这会改变方向。

票数 7
EN

Stack Overflow用户

发布于 2018-09-05 18:20:11

使用外部提供程序配置identtyserver时,通常在AuthenticationOptions中将AutheticationType设置为某些字符串。就像下面

代码语言:javascript
复制
           app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions
            {
                AuthenticationType = "Google",
                Caption = "Sign-in with Google",
                SignInAsAuthenticationType = signInAsType,

                ClientId = ConfigurationManager.AppSettings["google:clientid"],
                ClientSecret = ConfigurationManager.AppSettings["google:clientsecret"],
            });

然后,在客户端应用程序中,可以将acrvalues设置为身份验证类型,如下所示

代码语言:javascript
复制
        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {           

            Notifications = new OpenIdConnectAuthenticationNotifications
            {            

                RedirectToIdentityProvider = (n) =>
                {
                    if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.AuthenticationRequest)
                    {
                        if(n.Request.Uri == "someurl")
                         {
                        //set acrvalues. the value of the `idp`, (which is `Google` in this case) must match with the `AutheticationType` you set in IdentityServer
                        n.ProtocolMessage.AcrValues = "idp:Google"; 
                        }
                    }


                    return Task.FromResult(0);
                }
            }

还请注意,idp值区分大小写。

另一种选择(我没有尝试过)。而不是设置idp,而是在客户端应用程序中设置tenant

代码语言:javascript
复制
   n.ProtocolMessage.AcrValues = "tenant:" + n.Request.Uri.ToString();

正如@TheRock提到的,在IndentityServer中,检查SignInMessage中的租户并覆盖Idp

代码语言:javascript
复制
public override Task PreAuthenticateAsync(PreAuthenticationContext context)
{
   if(context.SignInMessage.Tenant = "sometenant")
   {
      context.SignInMessage.IdP = "Google";
      return base.PreAuthenticateAsync(context);  
   }
}

这样,在不断添加新的外部提供程序时,不必更改客户端应用程序中的代码。您只需要更新IndentityServer代码。如果您有多个客户端应用程序连接到同一个身份服务器,这将特别有帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29943977

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档