Выполнение запроса GET:
https://accounts.google.com/o/oauth2/v2/auth?access_type=offline
&client_id=XXXXX.apps.googleusercontent.com
&nonce=XXXX
&prompt=consent
&redirect_uri=http://localhost:3000/api/oauth/gmail/callback
&response_type=code
&scope=https://mail.google.com/
&state=XXXXX
Получение данных на localhost:3000
после перенаправления:
{"access_token"=> "ya29...",
"expires_in"=>3599,
"refresh_token"=>"1//0c...",
"scope"=>"https://mail.google.com/",
"token_type"=>"Bearer"}
здесь "expires_in"=>3599
означает, что access_token
не будет действительным в 1 час.
Хорошо, теперь отправляем запрос на refre sh it:
# ruby code:
request_params = {
client_id: 'XXXXX.apps.googleusercontent.com',
client_secret: 'XXXX',
grant_type: 'refresh_token',
refresh_token: '1//0c...',
}
res = Net::HTTP.post_form(URI.parse(url), request_params)
И получаем HTTP-код 307 Temporary Redirect
с location
заголовком:
https://accounts.google.com/signin/oauth?access_type=offline",
&client_id
&nonce=XXXX
&prompt=consent
&redirect_uri=http://localhost:3000/api/oauth/gmail/callback
&response_type=code
&scope=https://mail.google.com/
&state=XXXXX
&o2v=2
&as=XXXX
Это означает, что пользователь моей веб-службы должен go каждый час проходить процесс разрешения Google OAuth. Почему?
Может быть, из-за этого:
?