实现自己的oauth2服务器和api服务器

时间:2016-01-12 10:25:34

标签: node.js oauth-2.0 oauth2orize

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

enter image description here

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

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

我们正在考虑将用户和角色保留在oauth方面,但我们需要在给api呼叫响应之前在api端检查它们。

我们正在尝试将其用于身份验证以及cms和移动应用。我们是在正确的轨道上还是遗失任何东西。

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

(我在.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);
                        }
                    }

            });

(根据我的经验)。但是如果你愿意,可以选择在你的&#34; startup&#34;中配置Provider。文件:

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

            });

&#34; CustomOAuthBearerProvider&#34;继承&#34; IOAuthBearerAuthenticationProvider&#34;具有RequestToken()方法的预定义签名的接口,并且在对token进行任何验证之前调用此方法。所以我认为您可以将它用于Token上的自定义验证操作,然后发送令牌进行OAuth验证。

相关问题