相关疑难解决方法(0)

ASP.NET核心中的OAuth授权服务

在Web API 2中,您曾经能够通过中间件设置OAuth授权服务器来创建端点以发出令牌,如下所示:

//Set up our auth server options.
var OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new SimpleAuthorizationServerProvider()
            };

 // Sets up the token issue endpoint using the options above
 app.UseOAuthAuthorizationServer(OAuthServerOptions);
Run Code Online (Sandbox Code Playgroud)

也许我错过了它,但我想弄清楚如何在ASP.NET Core中做到这一点.我查看了源代码(https://github.com/aspnet/Security),但我真的没有看到类似的东西.有没有新的方法来实现这一目标?我是否需要创建一个控制器并自己完成?

我看到如何通过中间件设置OAuth身份验证,但这涉及我从API发出声明的授权部分.

asp.net oauth asp.net-core-mvc asp.net-core

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

覆盖AccessTokenExpireTimeSpan

是否可以覆盖自定义OAuthAuthorizationServerProvider上特定故障单的默认AccessTokenExpireTimeSpan?所有其他票证的默认到期时间为15分钟.

public public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
    ...
    var ticket = new AuthenticationTicket(identity, properties);

    if (condition)
    {
        ticket.Properties.IssuedUtc = DateTime.UtcNow;
        ticket.Properties.ExpiresUtc = DateTime.UtcNow.AddDays(14);
    }

    context.Validated(ticket);
}
Run Code Online (Sandbox Code Playgroud)

条件== true的生成标记具有默认的到期时间(15分钟).我不想更改context.Options.AccessTokenExpireTimeSpan,因为它影响所有令牌,这不是主意.

oauth-2.0 asp.net-web-api2

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