相关疑难解决方法(0)

如何验证通过cookie传递的JWT?

UseJwtBearerAuthenticationASP.NET Core中的中间件可以轻松验证Authorization标头中传入的JSON Web令牌.

如何验证通过cookie而不是标头传递的JWT?有点像UseCookieAuthentication,但对于只包含JWT的cookie.

cookies jwt asp.net-core

22
推荐指数
3
解决办法
1万
查看次数

如何通过Owin OAuthBearerAuthentication验证访问令牌?

我想要的是:

  1. 令牌生成器使用OAuthAuthorizationServer和令牌使用者使用OAuthBearerAuthentication(验证访问令牌).
  2. 使用OWIN管道来管理所有东西,令牌东西和web api的东西.

代码怎么样:

public void Configuration(IAppBuilder app)
{
    app.UseOAuthAuthorizationServer(new OAuthAuthorizationServerOptions
    {
        AuthorizeEndpointPath = "/Authorize",
        AllowInsecureHttp = true,
        Provider = new OAuthAuthorizationServerProvider 
        {
            OnGrantCustomExtension = GrantCustomExtension,
            OnValidateClientRedirectUri = ValidateClientRedirectUri,
            OnValidateClientAuthentication = ValidateClientAuthentication,
        }
    });

    app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions
    {
        Provider = new OAuthBearerAuthenticationProvider 
        { 
            //Handles applying the authentication challenge to the response message.
            ApplyChallenge=MyApplyChallenge,

            //Handles processing OAuth bearer token.
            RequestToken=MyRequestToken,

            //Handles validating the identity produced from an OAuth bearer token.
            ValidateIdentity = MyValidateIdentity,
        }
    });

    app.UseWebApi(new WebApplication3.Config.MyWebApiConfiguration());
}
Run Code Online (Sandbox Code Playgroud)

问题是什么:

  1. 的3个属性OAuthBearerAuthenticationProvider …

asp.net oauth-2.0 asp.net-web-api owin

9
推荐指数
1
解决办法
1万
查看次数

存储/验证 .net core api 中 HttpOnly cookie 中存储的 JWT 令牌

我将基于 jwt 的身份验证添加到我的 api,将令牌添加到标头(授权:Bearer {tokenhere})。

我研究了如何在客户端存储它,最推荐的方法是使用 HttpOnly cookie,它设置在服务器上,因此客户端代码无法访问它。浏览器将获取它并将其附加到将来的请求中。

为此,服务器必须在响应中写入此 cookie,并能够验证它而不是标头中的令牌(授权:Bearer {tokenhere})。

我该如何设置?我搜索了how和low,但没有找到这方面的教程,它要么是cookie,要么是jwt,从来没有将jwt存储为httponly cookie。

cookies authorization jwt asp.net-core

6
推荐指数
2
解决办法
9577
查看次数

从 ASP.NET Core 中的不同 HTTP 标头读取 JWT 令牌

在 ASP.NET Core API 项目中,我需要验证位于与 Authorization 标头不同的标头中的另一个 JWT Bearer 令牌。例如,假设发送一个 GET 请求来获取产品,/api/products并在名为 的标头中包含承载令牌AccessToken

curl --location --request GET 'https://localhost/api/products' \
--header 'AccessToken: <bearer_token>'
Run Code Online (Sandbox Code Playgroud)

我引用Microsoft.AspNetCore.Authentication.JwtBearer包并在 API 项目中设置身份验证,如下所示:

curl --location --request GET 'https://localhost/api/products' \
--header 'AccessToken: <bearer_token>'
Run Code Online (Sandbox Code Playgroud)

但是,我在JwtBearerOptions Class中找不到有关标头名称的任何内容。

如何配置 JWT 身份验证以从名为“AccessToken”的标头读取 JWT? 是否可以使用 Microsoft.AspNetCore.Authentication.JwtBearer 包?

c# jwt asp.net-core asp.net-core-authenticationhandler

5
推荐指数
1
解决办法
1万
查看次数