I am trying to use the Google Calendar API to demonstrate the OAuth2 integration that we will need to do with another third party. I use the DotNetOpenAuth library, and I managed to get the initial redirect to Google to request Allow / Deny and return the authorization code.
Now I need to get the access token and update the token, but it seems to me that I get the access token back, refresh token is null.
This is my controller action method when Google redirects back after the user accepts or rejects:
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 set oAuthClient identical to what I did above and use this method:
oAuthClient.RequestUserAuthorization(new[] { "https://www.googleapis.com/auth/calendar" }, returnUrl);
source
share