简体   繁体   English

承载令牌授权

[英]Bearer token Authorization

I am having a problem with Identity Server 3 and bearer token authentication. 我在Identity Server 3和承载令牌身份验证方面遇到问题。

Basically, I can call my Web API methods with an expired access token and the Web API authenticates the user and returns the data. 基本上,我可以使用过期的访问令牌来调用Web API方法,并且Web API会对用户进行身份验证并返回数据。

I have set my client to have an access token lifetime of 360 seconds and this indeed is the case when I check the claim. 我已将我的客户端设置为具有360秒的访问令牌生存期,这确实是我检查索赔时的情况。

How do I go about ensuring my Web API cannot be called with an expired access token. 如何确保无法使用过期的访问令牌调用We​​b API。 Do I need to set something in my IdentityServerBearerTokenAuthenticationOptions ? 我是否需要在IdentityServerBearerTokenAuthenticationOptions进行设置?

Thanks. 谢谢。

When the request comes in the very first thing we do is check if the identity is authenticated and that the authentication type is "Bearer". 当请求到来时,我们要做的第一件事就是检查身份是否已通过身份验证,并且身份验证类型为“承载”。

    private static bool RequestIsAuthenticated(HttpActionContext actionContext)
    {
        return (actionContext.RequestContext.Principal.Identity.AuthenticationType == "Bearer" && actionContext.RequestContext.Principal.Identity.IsAuthenticated);
    }

If this returns false we return a HttpStatusCode.Unauthorized. 如果返回false,则返回HttpStatusCode.Unauthorized。

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

相关问题 带有授权标头和不记名令牌的 Blazor 导航 - Blazor navigation with authorization header and bearer token 使用NEST elasticsearch和C#的授权承载令牌 - Authorization bearer token with NEST elasticsearch and C# HttpClient 未在 .Net Core 3.1 中发送授权承载令牌 - HttpClient not sending authorization Bearer token in .Net Core 3.1 未使用IdentityServer3承载令牌调用We​​bAPI授权属性 - WebAPI Authorization Attribute not being called with IdentityServer3 Bearer Token c# - 如何在c#中使用“授权”、“承载”、令牌创建指向URL的websocket - How to create a websocket to a URL using "Authorization", "Bearer", token in c# Web API 2 中非常基本的承载令牌身份验证和授权 - Very basic bearer token authentication and authorization in Web API 2 在Hangfire中设置JWT承载令牌授权/认证 - Set up JWT Bearer Token Authorization/Authentication in Hangfire 从没有承载前缀的授权 header 中获取访问令牌 - Fetch access token from authorization header without bearer prefix ASP.Net Core 的自定义承载令牌授权 - Custom Bearer Token Authorization for ASP.Net Core Microsoft.Owin.Security.Oauth承载令牌授权拦截 - Microsoft.Owin.Security.Oauth Bearer Token Authorization Interception
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM