Google令牌验证通话已陷入僵局?

问题描述 投票:0回答:1

我有一个C#后端控制器方法,可以使用google身份验证来验证Google ID令牌。它在部署到我的测试服务器后首先工作,但过了一段时间,它会遇到死锁情况(我相信)。没有错误,它只是挂在VerifyGoogleToken上。

using Google.Apis.Auth;
using Google.Apis.Auth.OAuth2;

    [HttpPost]
    public async Task<string> VerifyGoogleToken(string Token)
    {
        var verifyUser = Task.Run(() => VerifyToken(Token).Result);
        await Task.WhenAll(verifyUser);
        string returnValue = verifyUser.Result.ToString();
        return returnValue;
    }

    private async Task<string> VerifyToken(string Token)
    {
        string ReturnValue = "InvalidToken";
        GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(Token);
        if (payload.HostedDomain == "mydomain.com" && payload.EmailVerified == true && payload.Audience.ToString() == ClientID && (payload.Issuer == "accounts.google.com" || payload.Issuer == "https://accounts.google.com"))
        {
            ReturnValue = "ValidToken";
        }
        return ReturnValue;
    }

我也试过这个:

[HttpPost]
public async Task<string> VerifyGoogleToken(string Token)
{
    string returnValue = await VerifyToken(Token)
    return returnValue;
}

private async Task<string> VerifyToken(string Token)
{
    string ReturnValue = "InvalidToken";
    GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(Token);
    if (payload.HostedDomain == "mydomain.com" && payload.EmailVerified == true && payload.Audience.ToString() == ClientID && (payload.Issuer == "accounts.google.com" || payload.Issuer == "https://accounts.google.com"))
    {
        ReturnValue = "ValidToken";
    }
    return ReturnValue;
}

这个:

[HttpPost]
public string VerifyGoogleToken(string Token)
{
    string returnValue = VerifyToken(Token);
    return returnValue;
}

private async Task<string> VerifyToken(string Token)
{
    string ReturnValue = "InvalidToken";
    GoogleJsonWebSignature.Payload payload = await GoogleJsonWebSignature.ValidateAsync(Token);
    if (payload.HostedDomain == "mydomain.com" && payload.EmailVerified == true && payload.Audience.ToString() == ClientID && (payload.Issuer == "accounts.google.com" || payload.Issuer == "https://accounts.google.com"))
    {
        ReturnValue = "ValidToken";
    }
    return ReturnValue;
}

到目前为止没有任何工作。

任何帮助表示赞赏。

c# asp.net async-await google-identity
1个回答
0
投票

我相信你可以调用验证的次数是有限的,但我并不完全知道这个限制。我的代码用于每隔30秒调用一次验证,例如获取用户的ID /电子邮件等。这个设置在几个小时后停止工作。由于我重写了代码,每个连接只调用几次验证,因此验证工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.