Я пытаюсь интегрировать Календарь Google в свое приложение, и у меня возникают проблемы с авторизацией OAuth, передающей RefreshToken. Я получаю AccessToken без проблем, но свойство RefreshToken равно null. См. строку с пометкой «ОШИБКА ЗДЕСЬ :», где у меня возникла проблема
. Мой контроллер Asp.Net MVC (с именемOAuthController
)выглядит следующим образом:
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);
}
Я вижу в документах Google API, что мне нужно убедиться, что запрошенный access_type
установлен на offline
для отправки RefreshToken. Как мне установить это значение в моем запросе Authenticator?