Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法从IAAuthenticationTokenProvider调用context.SetError_C#_Oauth 2.0_Token_Owin - Fatal编程技术网

C# 无法从IAAuthenticationTokenProvider调用context.SetError

C# 无法从IAAuthenticationTokenProvider调用context.SetError,c#,oauth-2.0,token,owin,C#,Oauth 2.0,Token,Owin,我的应用程序中有一个OWIN对OAuth 2.0的简单实现,支持刷新令牌 void Receive(AuthenticationTokenReceiveContext context) 在这个方法中,如果刷新令牌无效,我想调用SetError(或类似的东西)来返回正确的json响应,而不是默认的“invalid_grant”,类型为AuthenticationTokenReceiveContext的上下文似乎不包含任何这样的方法。现在,我只是设置一个空票证,在我的grantrefreshtto

我的应用程序中有一个OWIN对OAuth 2.0的简单实现,支持刷新令牌

void Receive(AuthenticationTokenReceiveContext context)
在这个方法中,如果刷新令牌无效,我想调用SetError(或类似的东西)来返回正确的json响应,而不是默认的“invalid_grant”,类型为
AuthenticationTokenReceiveContext
的上下文似乎不包含任何这样的方法。现在,我只是设置一个空票证,在我的
grantrefreshttoken
方法中,我检查票证是否包含任何声明,如果没有,这意味着刷新令牌无效,我将从那里设置错误响应,如下所示

public override Task GrantRefreshToken(OAuthGrantRefreshTokenContext context)
{
    return Task.Run(() =>
    {
        var claimCount = context.Ticket.Identity.Claims.Count();

        if (claimCount > 0)
            context.Validated(context.Ticket.Identity);
        else
            RejectWithJson(context, new GeneralError { ErrorCode = GeneralErrorCode.InvalidRefreshToken, Message = "Invalid refresh token" }, HttpStatusCode.Unauthorized);
    });
}

有没有办法通过
Receive
method做到这一点?

你有没有想过=[“无效的补助金”只是描述得不够。