在介绍自定义用户服务之前先对IdentityServerServiceFactory说明下 Idr3的服务工厂

下面有很多idr3提供的接口服务,

如:ViewService、UserService、ClientStore 等很多,可以做很多的事情

其实它承载的不光是自身的接口服务,其实还提供了 服务注册 DI ,我们可以注册自己的接口服务实现

自定义用户服务只需要去实现 IUserService接口就行了

  factory.UserService = new Registration<IUserService, IdrConfig.UserServices>();

去看下IUserService接口中的方法

 //
        // 摘要:
        //     This method gets called when the user uses an external identity provider to authenticate.
        //     The user's identity from the external provider is passed via the `externalUser`
        //     parameter which contains the provider identifier, the provider's identifier for
        //     the user, and the claims from the provider for the external user.
        //
        // 参数:
        //   context:
        //     The context.
        Task AuthenticateExternalAsync(ExternalAuthenticationContext context);
        //
        // 摘要:
        //     This method gets called for local authentication (whenever the user uses the
        //     username and password dialog).
        //
        // 参数:
        //   context:
        //     The context.
        Task AuthenticateLocalAsync(LocalAuthenticationContext context);
        //
        // 摘要:
        //     This method is called whenever claims about the user are requested (e.g. during
        //     token creation or via the userinfo endpoint)
        //
        // 参数:
        //   context:
        //     The context.
        Task GetProfileDataAsync(ProfileDataRequestContext context);
        //
        // 摘要:
        //     This method gets called whenever identity server needs to determine if the user
        //     is valid or active (e.g. if the user's account has been deactivated since they
        //     logged in). (e.g. during token issuance or validation).
        //
        // 参数:
        //   context:
        //     The context.
        Task IsActiveAsync(IsActiveContext context);
        //
        // 摘要:
        //     This method is called prior to the user being issued a login cookie for IdentityServer.
        //
        // 参数:
        //   context:
        //     The context.
        Task PostAuthenticateAsync(PostAuthenticationContext context);
        //
        // 摘要:
        //     This method gets called before the login page is shown. This allows you to determine
        //     if the user should be authenticated by some out of band mechanism (e.g. client
        //     certificates or trusted headers).
        //
        // 参数:
        //   context:
        //     The context.
        Task PreAuthenticateAsync(PreAuthenticationContext context);
        //
        // 摘要:
        //     This method gets called when the user signs out.
        //
        // 参数:
        //   context:
        //     The context.
        Task SignOutAsync(SignOutContext context);
IUserService

相关文章: