5

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

在此处输入图像描述

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

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

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

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

4

2 回答 2

0

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

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

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

于 2016-01-21T10:20:13.913 回答
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);
                        }
                    }

            });

(根据我的经验)。但是,如果您愿意,可以选择在“启动”文件中配置 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 验证。

于 2016-04-14T13:30:37.850 回答