错误:“invalid_grant”,描述:“无效的JWT:令牌必须是一个短期令牌并且在合理的时间范围内”,Uri:“”无效的授权

问题描述 投票:2回答:2

我试图在谷歌服务帐户的帮助下访问谷歌日历,但我得到了belloing错误

Google.Apis.dll中出现“Google.Apis.Auth.OAuth2.Responses.TokenResponseException”类型的例外,但未在用户代码中处理

我得到的错误:"invalid_grant", Description:"Invalid JWT: Token must be a short-lived token and in a reasonable timeframe", Uri:""

        string credPath = "key path";

        String serviceAccountEmail = [email protected]";

        var certificate = new X509Certificate2(credPath, "notasecret", X509KeyStorageFlags.Exportable);

        ServiceAccountCredential credential = new ServiceAccountCredential(
           new ServiceAccountCredential.Initializer(serviceAccountEmail)
           {
               Scopes = new[] {  CalendarService.Scope.CalendarReadonly,
                                CalendarService.Scope.Calendar}
           }.FromCertificate(certificate));

        // Create the service.
        var service = new CalendarService(new BaseClientService.Initializer()
        {
            HttpClientInitializer = credential,
            ApplicationName = "HRTool",
        });


        var events = service.Events.List("my calaender id").Execute();
google-calendar-api
2个回答
6
投票

Invalid grant

当您尝试使用刷新令牌时,以下内容将返回invalid_grant错误:

首先,请使用服务器时钟检查同步问题,有关其他信息,请参阅poor synchronization of the computer's clock答案。其次,检查刷新令牌和旧令牌的处理。某些流程包括其他步骤,例如使用刷新令牌获取新的访问令牌。有关各种类型应用程序的流程的详细信息,请参阅Google的OAuth 2.0 documentation

希望这可以帮助!


0
投票

如果您收到“无效的JWT签名”错误。如果您使用的是P12证书,请确认您使用的客户密钥是否正确。

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