【发布时间】:2017-04-26 16:25:28
【问题描述】:
我正在尝试按照本指南设置授权服务器: http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/
但是,我想将我的本地服务器(即运行项目的服务器)指定为 CustomJwtFormatting 的 issuer。所以,在 Startup.cs 我使用:
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 类,代码是这样的:
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/token 发送 POST 请求时出现 404 错误:
在 ASP.NET 中正确实现本地服务器上颁发者的最佳方式是什么?
【问题讨论】: