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

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

在这里输入图像描述

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

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

我们正在考虑在oauth方面保留用户和angular色,但是我们需要在给api调用响应之前在api方面检查它们。

我们正在尝试将它用于cms和移动应用程序的身份validation。 我们是正确的还是错过了任何东西。

我看了更多的细节,我得到了Oauth2orizeRecipes中的tokeninfo实现。

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

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

(我在.Net面临类似的情况,所以在这方面)

不,如果您使用的是oauth,则不必编写新的validation令牌方法。 由于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); } } }); 

(根据我的经验)。 但是,如果你想,可以select在你的“启动”文件中configurationProvider:

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

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