【问题标题】:Refresh Token Expiration time Google calendar刷新令牌过期时间谷歌日历
【发布时间】:2013-09-13 23:39:04
【问题描述】:

谁能告诉我通过 OAuth2 生成刷新令牌的到期时间。实际上它通常返回 2 个参数访问令牌和刷新令牌。如果访问令牌过期,我们使用刷新令牌来生成新的访问令牌。但是 Google Calendar Version3,我使用刷新令牌来调用日历 API。但是在这里我遇到了令牌过期的问题。因此,任何人都可以建议我在令牌过期时该怎么办。据我所知,刷新令牌没有到期时间。请检查以下代码以使用刷新令牌创建日历服务:-

 private CalendarService CreateService(string token)
{        
    KeyValuePair<string, string> credentials = Common.Get3LOCredentials();
    var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description);
    provider.ClientIdentifier = credentials.Key;
    provider.ClientSecret = credentials.Value;
    var auth = new Google.Apis.Authentication.OAuth2.OAuth2Authenticator<NativeApplicationClient>(provider, (p) => GetAuthorization(provider, token));
    CalendarService service = new CalendarService(new BaseClientService.Initializer()
    {
        Authenticator = auth,
        ApiKey = ConfigurationManager.AppSettings["APIkey"].ToString(),
        GZipEnabled = false
    });       
    return service;
}

private static IAuthorizationState GetAuthorization(NativeApplicationClient arg, String Refreshtoken)
{
    IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
    state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
    state.RefreshToken = Refreshtoken;        
    return state;
}

【问题讨论】:

    标签: asp.net oauth-2.0 google-calendar-api


    【解决方案1】:

    刷新令牌不会过期,但可以撤销。您,令牌处理程序可以revoke the token yourself programatically 或最终用户可以revoke the token in their account settings。确保您是正确的using the refresh token to get a new access token,并且您没有尝试使用已过期的访问令牌。

    您能否编辑您的问题以显示您遇到的确切错误?

    【讨论】:

    • 感谢我们的回复。我没有使用访问令牌,而是直接使用刷新令牌来创建日历服务。以前它工作正常。请检查我的答案中的代码,我如何使用刷新令牌创建日历服务。
    猜你喜欢
    • 1970-01-01
    • 2021-05-06
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2013-04-16
    • 2017-09-29
    • 2012-05-10
    相关资源
    最近更新 更多