6

I'm trying to use Google's Calendar API to demo out an OAuth2 integration that we'll need to do with another third party. I'm using the DotNetOpenAuth library, and I've been able to get the initial redirect to Google for the Allow / Deny prompt and get the authorization code back.

I now need to get the access token and refresh token, but I only seem to get an access token back, refresh token is null.

This is my controller action method where Google redirects back to after the user Accepts or Denies:

public ActionResult ProcessResponse(string state, string code, string error)
{
  var oAuthClient =
    new WebServerClient(
      new AuthorizationServerDescription
      {
        TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"),
        AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth"),
        ProtocolVersion = ProtocolVersion.V20
      },
      _applicationId, 
      _secret)
      {
        AuthorizationTracker = new TokenManager()
      };


  var authState = oAuthClient.ProcessUserAuthorization();

  var accessToken = authState.AccessToken;
  var refreshToken = authState.RefreshToken;

  return View(new[] { accessToken, refreshToken });
}

Any ideas?

EDIT:

To get the authorization code, I setup the oAuthClient identically to what I did above, and use this method:

oAuthClient.RequestUserAuthorization(new[] { "https://www.googleapis.com/auth/calendar" }, returnUrl);
Andy
  • 8,432
  • 6
  • 38
  • 76
  • Please edit your question to include the way you submit the original authorization request. – Andrew Arnott Jun 28 '12 at 23:28
  • @AndrewArnott Done; it just a single call to `RequestUserAuthorization`. – Andy Jun 29 '12 at 12:30
  • Can you include more context to your request? For example, how you construct the `oAuthClient` that you use to send the request? – Andrew Arnott Jul 02 '12 at 22:16
  • @AndrewArnott "To get the authorization code, I setup the oAuthClient identically to what I did above" – Andy Jul 03 '12 at 12:28
  • I know this is a somewhat old question but do you know what version of dotnetopenauth you are using. My options for Protocol version are only V10 and V10a – BillPull May 09 '14 at 18:29

1 Answers1

1

I had a similar problem, and solved mine by hand-coding the HttpRequest and HttpResponse handling. See code at: https://stackoverflow.com/a/11361759/29156

Community
  • 1
  • 1
Jeff Fritz
  • 9,821
  • 7
  • 42
  • 52