[英]OpenID Connect lightweight library
I'm looking for OpenID Connect (OIDC) Relying Party lightweight library that will have these routines implemented. 我正在寻找将实现这些例程的OpenID Connect(OIDC)依赖方轻量级库 。
The only OIDC flow to be supported is so called " implicit flow " where server answers with "id_token" (and "access_token" if requested) right from authorization endpoint ( spec link ). 要支持的唯一OIDC流是所谓的“ 隐式流 ”,其中服务器从授权端点( 规范链接 )回答“id_token”(以及“access_token”,如果请求)。
Searching over NuGet repository seems to yield the only suitable option - OWIN middleware, and even though I can confirm it works, it would be better to have lightweight alternative. 搜索NuGet存储库似乎只能产生唯一合适的选项--OWIN中间件,即使我可以确认它有效,但最好还是选择轻量级替代品。
Just sharing what worked for me. 只是分享对我有用的东西。
To get 1st goal accomplished NuGet package called Thinktecture.IdentityModel.Client
( link ) can be used (package from IdentityServer creators that is incredible itself). 为了获得第一个目标,可以使用名为
Thinktecture.IdentityModel.Client
( link )的NuGet包(来自IdentityServer创建者的包本身就是令人难以置信的)。 An example that shows basic usage is below. 显示基本用法的示例如下。
var client = new OAuth2Client(new Uri(AuthorizeEndpointUrl));
string url = client.CreateAuthorizeUrl(
clientId: ClientId,
redirectUri: RedirectUri,
responseType: "id_token",
responseMode: "form_post",
nonce: Guid.NewGuid().ToString(),
additionalValues: additionalValues);
As to parsing and validation of the JWT received from OIDC Identity Provider the System.IdentityModel.Tokens.Jwt
( link ) Microsoft's NuGet package is a way to go. 至于从OIDC身份提供者收到的JWT的解析和验证,
System.IdentityModel.Tokens.Jwt
( 链接 )微软的NuGet包是一种方法。 The code snippet is bellow as well. 代码片段也是如此。
var parameters = new TokenValidationParameters()
{
IssuerSigningTokens = GetSigningTokens(MetadataEndpointUrl),
ValidAudience = ValidAudience,
ValidIssuer = ValidIssuer,
};
var tokenHandler = new JwtSecurityTokenHandler();
SecurityToken validated;
tokenHandler.ValidateToken(jwt, parameters, out validated);
return validated as JwtSecurityToken;
This all lightweight and keeps your application clean from unnecessary dependencies. 这一切都是轻量级的,可以保护您的应用程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.