zoukankan      html  css  js  c++  java
  • IdentityServer4 sign-in

    原文地址

    Sign-in

    IdentityServer 代表 user 分配token之前,user必须登录IdentityServer

    使用 cookie 进行身份认证的方式,是通过 Asp.Net Core 的 cookie authentication handler 实现的。

    IdentityServer 注册了两个 cockie handler(一个用来身份认证中的session,另外用于一个temporary external cookie)。两者是默认配置使用的,可以通过 IdentityServerConstants类获得他们的名称(DefaultCookieAuthenticationSchemeExternalCookieAuthenticationScheme)

    以上的cookie只提供一个基本的配置(过期时间和 sliding),也可以通过注册自己的cookie handler来控制更多的内容。当使用ASP.NET Core中的AddAuthentication时,IdentityServer使用与AuthenticationOptions上配置的DefaultAuthenticateScheme匹配的cookie处理程序。

    ConfigureService 时,在DI中注入 IdentityServer (通过AddIdentityServer)之后,再天剑自定义的 cookie authentication handler

    services.AddIdentityServer()
        .AddInMemoryClients(Clients.Get())
        .AddInMemoryIdentityResources(Resources.GetIdentityResources())
        .AddInMemoryApiResources(Resources.GetApiResources())
        .AddDeveloperSigningCredential()
        .AddTestUsers(TestUsers.Users);
    
    services.AddAuthentication("MyCookie")
        .AddCookie("MyCookie", options =>
        {
            options.ExpireTimeSpan = ...;
        });
    

    NOTE IdentityServer 内部会调用 AddAuthenticationAddCookie方法,并使用 IdentityServerConstants.DefaultCookieAuthenticationScheme 的自定义 Scheme,所以需要在调用 AddIdentityServer 之后再去调用这两个方法进行覆盖重写。

    用户登录接口和身份认证管理系统

    IdentityServer 没有提供 user 身份认证的用户界面或者用户数据库。自行开发。

    Login 的流程

    Hello

    NOTE open-redirect attack,确保 returnUrl 是合法的, 参考 interaction service

    Login Context

    interaction service 调用 GetAuthorizationContextAsync 可以在登录页面获取到request的上下文信息(比如:client, 提示参数, idP(identity provider) 提示等等),以便于自定义登录的体验。

    在 Asp.Net 的HttpContext中有身份认证相关的扩展方法,用于生成 身份认证的 cookie 以及用户登录。 authentication 的scheme 必须符合cookie handler中配置的值。

    当用户登录之后,至少要生成 sub 以及 name 的 claim。 IdentityServer 同样也在 HttpContext中 提供几个 SignInAsync 扩展方法,使得使用起来更方便。

    也可以生成 idp claim(identity provider 的 name),amr claim(authentication method使用),和/或 auth_time claim(用户authentication的时间)。如果不提供这些值, identityServer 会提供默认的值。

  • 相关阅读:
    docker怎么修改之前run时的env
    yum安装mysql
    springboot服务的Dockerfile
    openssh升级到8.4
    rpm与yum执行无反应
    ubuntn离线安装docker-ce
    centos7部署docker
    解决5版本的elasticsearch-head连接6版本的elasticsearch查询不到数据问题
    docker搭建elasticsearch:7.6.2并开启x-pack
    原生js 实现图片的拖拽缩放
  • 原文地址:https://www.cnblogs.com/ArvinZhao/p/11352735.html
Copyright © 2011-2022 走看看