【问题标题】:implementing own oauth2 server and api server实现自己的 oauth2 服务器和 api 服务器
【发布时间】:2016-04-16 21:58:51
【问题描述】:

我们正在尝试实现 oauth 2 服务器和 api 服务器(两者都是不同的服务器)。 (全部使用nodejs)

我们正在使用https://github.com/FrankHassanabad/Oauth2orizeRecipes授权码流程

我们是否需要在 oauth 服务器中编写 new validateToken 函数,然后从 api 端点击它来仅验证该用户。

我们正在考虑将用户和角色保留在 oauth 端,但我们需要在 api 端检查它们,然后再给出 api 调用响应。

我们正在尝试将其用于身份验证以及 cms 和移动应用程序。我们是在正确的轨道上还是错过了什么。

【问题讨论】:

    标签: node.js oauth-2.0 oauth2orize


    【解决方案1】:

    (我在 .Net 中遇到过类似的情况,所以在这种情况下)

    不,如果您使用的是 oauth,则不必编写新的验证令牌方法。 作为 OAuthBearerAuthenticationProvider 在幕后执行此操作

    app.UseJwtBearerAuthentication(
                new JwtBearerAuthenticationOptions
                {
                    AuthenticationMode = AuthenticationMode.Active,
                    AllowedAudiences = new[] { audience },
                    IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                    {
                        new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
                    },
                    Provider = new OAuthBearerAuthenticationProvider
                        {
                            OnValidateIdentity = context =>
                            {
                                context.Ticket.Identity.AddClaim(new System.Security.Claims.Claim("newCustomClaim", "newValue"));
                                return Task.FromResult<object>(null);
                            }
                        }
    
                });
    

    (根据我的经验)。但是,如果您愿意,可以选择在“启动”文件中配置 Provider:

    app.UseJwtBearerAuthentication(
                new JwtBearerAuthenticationOptions
                {
                    AuthenticationMode = AuthenticationMode.Active,
                    AllowedAudiences = new[] { audience },
                    IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
                    {
                        new SymmetricKeyIssuerSecurityTokenProvider(issuer, secret)
                    },
                    Provider = new CustomOAuthBearerProvider()                        
    
                });
    

    “CustomOAuthBearerProvider”继承了“IOAuthBearerAuthenticationProvider”接口,该接口具有RequestToken()方法的预定义签名,并且该方法在任何令牌验证之前被调用。所以我认为你可以将它用于对 Token 的自定义验证操作,然后发送令牌进行 OAuth 验证。

    【讨论】:

      【解决方案2】:

      我查看了更多细节,我在 Oauth2orizeRecipes 中获得了 tokeninfo 实现。

      https://github.com/FrankHassanabad/Oauth2orizeRecipes/wiki/Token-Info-Endpoint

      我还有几点不清楚,将再次更新答案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-12-12
        • 1970-01-01
        • 2015-04-12
        • 1970-01-01
        • 1970-01-01
        • 2015-05-11
        • 2019-04-01
        相关资源
        最近更新 更多