JWT-配置授权服务器并将发行者设置为自身 [英] JWT - Configuring a Authorization Server and setting the issuer as itself
问题描述
我正在尝试按照本指南设置授权服务器: http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/
I am trying to set up an Authorization Server following this guide: http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/
但是,我想将本地服务器(即运行项目的服务器)分配为 CustomJwtFormatting 的发布者.因此,在Startup.cs中,我使用:
However, I want to assign my local server (i.e. the server that the project runs on) as the issuer for CustomJwtFormatting. So, in Startup.cs I use:
public void ConfigureOAuth(IAppBuilder app)
{
var issuer = HttpContext.Current.Request.Url.Scheme + System.Uri.SchemeDelimiter + HttpContext.Current.Request.Url.Host
+ (HttpContext.Current.Request.Url.IsDefaultPort ? "" : ":" + HttpContext.Current.Request.Url.Port); // get the host name with the port
OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
//For Dev enviroment only (on production should be AllowInsecureHttp = false)
//TODO: Make it false before going live
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/oauth2/token"),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(30),
Provider = new CustomOAuthProvider(),
AccessTokenFormat = new CustomJwtFormat(issuer)
};
// OAuth 2.0 Bearer Access Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
}
对于CustomJwtFormat类,代码如下:
And for the CustomJwtFormat class, the code is like that:
var issuer = HttpContext.Current.Request.Url.Scheme + System.Uri.SchemeDelimiter + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.IsDefaultPort ? "" : ":" + HttpContext.Current.Request.Url.Port); // get the host name with the port
var token = new JwtSecurityToken(_issuer, audienceId, data.Identity.Claims, issued.Value.UtcDateTime, expires.Value.UtcDateTime, signingKey);
但是,当我向 http://127.0.0.1/oauth2发送POST请求时,出现404错误/token :
在ASP.NET中正确实现本地服务器发行者的最佳方法是什么?
What is the best way to achieve that issuer-on-the-local-server thing correctly in ASP.NET?
推荐答案
好吧,我已经尝试将null分配给发行人,例如
Well, I have tried assigning null to the issuer like
var issuer = null;
//var issuer = HttpContext.Current.Request.Url.Scheme + System.Uri.SchemeDelimiter + HttpContext.Current.Request.Url.Host + (HttpContext.Current.Request.Url.IsDefaultPort ? "" : ":" + HttpContext.Current.Request.Url.Port); // get the host name with the port`
它奏效了.
这篇关于JWT-配置授权服务器并将发行者设置为自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!