首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何创建facebook喜欢自己的原生SSO应用程序?

如何创建facebook喜欢自己的原生SSO应用程序?
EN

Stack Overflow用户
提问于 2020-05-31 23:55:37
回答 1查看 303关注 0票数 0

首先,很抱歉可能会有重复,我相信这个问题已经被问了很多次了,以各种形式出现,但我找不到明确的答案或方向如何开始。

我已经在identityserver4上构建了oidc,它已经与web和移动客户端一起投入生产。

我在这里并不要求实现细节,只是一些参考,如何创建应用程序的好例子,它将负责身份验证和会话管理,而不是浏览器。然后我可以创建sdk,将其安装在所有应用程序中,他们将通过这个本地sso应用程序共享身份验证逻辑。就像facebook一样。

EN

回答 1

Stack Overflow用户

发布于 2020-06-05 00:02:01

您所描述的本机体验称为资源所有者凭据授予

要在IdentityServer4中实现它,您需要实现IResourceOwnerPasswordValidator接口。

代码语言:javascript
代码运行次数:0
运行
复制
public class CustomResourceOwnerPasswordValidator : IResourceOwnerPasswordValidator
{
    public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
    {
        //Validate user's username and password. Insert your logic here.
        if(context.UserName == "admin" && context.Password == "admin@123")  
        context.Result = new GrantValidationResult("123", OidcConstants.AuthenticationMethods.Password);

        return Task.FromResult(0);
    }
}

然后配置IdentityServer4以使用它。

在Startup.cs中添加以下代码

代码语言:javascript
代码运行次数:0
运行
复制
            var builder = services.AddIdentityServer()
            .AddInMemoryIdentityResources(Config.Ids)
            .AddInMemoryApiResources(Config.Apis)
            .AddInMemoryClients(Config.Clients)
            .AddResourceOwnerValidator<CustomResourceOwnerPasswordValidator>();

并将客户端配置为使用授予的资源所有者凭据。

代码语言:javascript
代码运行次数:0
运行
复制
            new Client
            {
                ClientId = "resourceownerclient",

                AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
                AccessTokenType = AccessTokenType.Jwt,
                AccessTokenLifetime = 3600,
                IdentityTokenLifetime = 3600,
                UpdateAccessTokenClaimsOnRefresh = true,
                SlidingRefreshTokenLifetime = 30,
                AllowOfflineAccess = true,
                RefreshTokenExpiration = TokenExpiration.Absolute,
                RefreshTokenUsage = TokenUsage.OneTimeOnly,
                AlwaysSendClientClaims = true,
                Enabled = true,
                ClientSecrets=  new List<Secret> { new Secret("dataEventRecordsSecret".Sha256()) },
                AllowedScopes = {
                    IdentityServerConstants.StandardScopes.OpenId, 
                    IdentityServerConstants.StandardScopes.Profile,
                    IdentityServerConstants.StandardScopes.Email,
                    IdentityServerConstants.StandardScopes.OfflineAccess,
                    "dataEventRecords"
                }
            }

请注意AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials行。

下面是可能是IdentityServer与微软身份核心的实现的link

这是repositoryblog的演示。

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

https://stackoverflow.com/questions/62118792

复制
相关文章

相似问题

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