我试图这样做
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/MyCustomRoutepath/Token"),
Provider = new ApplicationOAuthProvider(),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
AllowInsecureHttp = true,
AuthenticationMode = AuthenticationMode.Active
};
不确定如何实现这一目标。看起来Web API会自动创建/ token路由。由于某些遗留原因,我无法使用它。我如何实现这一目标?我应该创建新的控制器方法和操作方法,并执行令牌端点应该做的任何事情吗?
请指出正确的方向。
答案 0 :(得分:0)
您的问题不清楚,但您可以将TokenEndpointPath
设置为您想要的自定义令牌路径
// Summary:
// The request path client applications communicate with directly as part of
// the OAuth protocol. Must begin with a leading slash, like "/Token". If the
// client is issued a client_secret, it must be provided to this endpoint.
public PathString TokenEndpointPath { get; set; }
虽然文档以/Token
为例,但您可以使用任何所需的路径。无需创建自己的控制器,因为owin中间件将在您指定的路径上处理auth。
var oAuthServerOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/MyCustomRoutepath/Token"),
Provider = new ApplicationOAuthProvider(),
AccessTokenExpireTimeSpan = TimeSpan.FromMinutes(60),
AllowInsecureHttp = true,
AuthenticationMode = AuthenticationMode.Active
};
// Token Generation
app.UseOAuthAuthorizationServer(oAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());