我正在尝试使用Bearer令牌和owin进行身份验证.
我可以使用授权类型发出令牌password并GrantResourceOwnerCredentials在AuthorizationServerProvider.cs中重写.
但我无法使用该Authorize属性访问控制器方法.
这是我的代码:
Startup.cs
public class Startup
{
public static OAuthAuthorizationServerOptions OAuthOptions { get; private set; }
// normal
public Startup() : this(false) { }
// testing
public Startup(bool isDev)
{
// add settings
Settings.Configure(isDev);
OAuthOptions = new OAuthAuthorizationServerOptions
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/Token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
Provider = new AuthorizationServerProvider()
};
}
public void Configuration(IAppBuilder app)
{
// Configure the db context, user manager and role manager …Run Code Online (Sandbox Code Playgroud)