Estoy intentando integrar Google Calendar en mi aplicación y tengo algunos problemas con la autorización de OAuth para pasar un RefreshToken. Recibo un AccessToken sin problema, pero la propiedad RefreshToken es nula. Ver la línea marcada "ERROR AQUÍ:" de donde yo estoy teniendo el problema¿Por qué no recibo un RefreshToken de una solicitud de Google OAuth?
controladorMi Asp.Net MVC (llamado OAuthController
) tiene el siguiente aspecto:
public ActionResult Index()
{
var client = CreateClient();
client.RequestUserAuthorization(new[] { "https://www.googleapis.com/auth/calendar" }, new Uri("http://localhost/FL.Evaluation.Web/OAuth/CallBack"));
return View();
}
public ActionResult CallBack()
{
if (string.IsNullOrEmpty(Request.QueryString["code"])) return null;
var client = CreateClient();
// Now getting a 400 Bad Request here
var state = client.ProcessUserAuthorization();
// ERROR HERE: The RefreshToken is NULL
HttpContext.Session["REFRESH_TOKEN"] = Convert.ToBase64String(Encoding.Unicode.GetBytes(state.RefreshToken));
return JavaScript("Completed!");
}
private static WebServerClient CreateClient()
{
return
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
}
, _GoogleClientId, _GoogleSecret);
}
veo en los documentos de la API de Google, que Necesito asegurarme de que el access_type
solicitado esté configurado en offline
para que se envíe un RefreshToken. ¿Cómo configuro este valor en mi solicitud de Autenticador?
He adelgazado mi código, y ahora recibo un error de 400 solicitudes incorrectas al intentar consultar a Google. –
He resuelto mi problema codificando manualmente las HttpRequests de ida y vuelta a Google. Voy a desinfectar y publicar el código como una respuesta –