1

I'm working with the MirrorQuickStart project for .NET and am running into problems with the refresh token. From what I can tell, it is not being used when the "notify" action comes in for a timeline subscription update.

Publishing the app to a dev server, basically as-is with the exception of updating the proper IDs and config info, the "notify" action works within the first hour, but after that, it stops responding until I refresh the web page and re-authenticate.

I have checked the StoredCredentials table on the database server, and it has the UserId, AccessToken and RefreshToken values populated. I also created a new mirror service in the standard app flow (since I'm not sure how to debug the notify flow and see any actual error messages that are occuring) and each time, I see the AccessToken and RefreshToken on the service.

MirrorService service = new MirrorService(new BaseClientService.Initializer
{
     Authenticator = Utils.GetAuthenticatorFromState(
             Utils.GetStoredCredentials(userId))
});

I've reviewed the DrEdit project for Drive and the flow seems to be basically the same in terms of the GEtAuthenticatorFromState and GetStoredCredentials methods.

This question seemed to most directly relate to the problem I'm encountering, but the answer didn't make sense in terms of the mirror project.

How to generate access token using refresh token through Google Drive SDK in .NET?

There's gotta be something simple I'm missing - just not sure as I'm fairly new to the OAuth flow.

Thank you.

Community
  • 1
  • 1
Kyle
  • 606
  • 5
  • 16
  • Do you get a specific error on the notify endpoint? – Alain Jun 24 '13 at 16:11
  • Been trying to debug a bit more - I think this logic should apply to the NotifyController, but I modified the MainController to use the "service" created by the code I included in the original post (I hard-coded by UserId for testing purposes). I'm getting a 401 Unauthorized error when I attempt to retrieve the list of subscriptions. In theory, that should be the same "service" that the NotifyController is attempting to use. – Kyle Jun 24 '13 at 17:15

1 Answers1

1

From the other SO answer you linked to, this seems to solve the problem in Model/Utils.cs:

        /// <summary>
        /// Returns the IAuthorizationState stored in the StoredStateClient instance.
        /// </summary>
        /// <param name="provider">OAuth2 client.</param>
        /// <returns>The stored authorization state.</returns>
        static public IAuthorizationState GetState(StoredStateClient provider)
        {
            provider.RefreshToken(provider.State);
            return provider.State;
        }

Notice the added line: provider.RefreshToken(provider.State). It's still unclear why the call to RefreshToken is required as this should be done automatically by the library...

Alain
  • 6,044
  • 21
  • 27
  • Thank you - I'll give this a try and see what happens. To answer your previous question, I was able to get an error from the notify endpoint. Here's the stack trace: at Google.Apis.Requests.Request.AsyncRequestResult.GetResponse() at Google.Apis.Requests.ClientServiceRequest`1.GetResponse() at Google.Apis.Requests.ClientServiceRequest`1.Fetch() at MirrorQuickstart.Controllers.NotifyController.HandleTimelineNotification(Notification notification, MirrorService service) System.Net.WebException: The remote server returned an error: (401) Unauthorized. – Kyle Jun 24 '13 at 22:02
  • The error seems related to the token not being refreshed. I'm still unsure why the explicit call needs to happen but will investigate more. – Alain Jun 24 '13 at 22:20
  • Ha - go figure, as soon as I start testing this, my daily usage quota is at the limit! I'll check into things tomorrow and hopefully mark this as an answer. Thanks again for the help, I appreciate it. – Kyle Jun 24 '13 at 23:11