简体   繁体   English

使用ASOS的访问令牌中的自定义用户数据

[英]Custom user data in access token with ASOS

I'm trying to impement the OpenID Connect server using AspNet.Security.OpenIdConnect.Server . 我试图使用AspNet.Security.OpenIdConnect.Server OpenID Connect服务器。

Is it possible to place some custom user data to the access token when issuing token at authorization Server and then retrieve it at Resource Server during token validation and request processing? 在授权服务器上发布令牌时,是否可以在访问令牌中放置一些自定义用户数据,然后在令牌验证和请求处理期间在资源服务器上检索它们?

Example: I want to write to the access token an IP address that was used to get token by user. 示例:我想将用于获取用户令牌的IP地址写入访问令牌。 Then at the resource server I want to compare current user IP address and IP address from token during token validation. 然后在资源服务器上,我想在令牌验证期间比较当前用户的IP地址和来自令牌的IP地址。

Another example: I want to write user's roles to token and then retrieve them in WebApi action filter or action itself 另一个示例:我想将用户的角色写入令牌,然后在WebApi操作过滤器或操作本身中检索它们

Consider simply storing the IP address as a claim: 考虑简单地将IP地址存储为声明:

identity.AddClaim("ip_addr", HttpContext.Connection.RemoteIpAddress.ToString(),
    OpenIdConnectConstants.Destinations.AccessToken);

Then, in your API controller, retrieve it using: 然后,在您的API控制器中,使用以下命令进行检索:

var address = User.FindFirst("ip_addr").Value;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM