1
votes

Can any one please tell me the expiration time for Refresh token generation through OAuth2. Actually it usually returns 2 parameter access token and refresh token. We used refresh token in order to generate a new access toke if access token get expired. But Google Calendar Version3, i am using refresh token in order to call the calendar API. But here i am getting a problem that token get expires. So can any one please suggest me what can i do when token get expires. According to me there is no expiration time for refresh token. Kindly check the code below for creation of calendar service using refresh token :-

 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;
}
1

1 Answers

3
votes

Refresh Tokens do not expire but they can be revoked. You, the token handler can revoke the token yourself programatically or the end user can revoke the token in their account settings. Make sure you are properly using the refresh token to get a new access token and you're not attempting to use an access token that has expired.

Can you edit your question to show the exact error you are getting?