2017-09-25 03:10:25 -04:00
|
|
|
module GoogleApi
|
|
|
|
class AuthorizationsController < ApplicationController
|
|
|
|
def callback
|
2017-10-02 04:13:46 -04:00
|
|
|
token, expires_at = GoogleApi::CloudPlatform::Client
|
2017-10-05 11:41:36 -04:00
|
|
|
.new(nil, callback_google_api_auth_url)
|
2017-10-02 04:13:46 -04:00
|
|
|
.get_token(params[:code])
|
|
|
|
|
|
|
|
session[GoogleApi::CloudPlatform::Client.session_key_for_token] = token
|
|
|
|
session[GoogleApi::CloudPlatform::Client.session_key_for_expires_at] =
|
|
|
|
expires_at.to_s
|
2017-09-25 03:10:25 -04:00
|
|
|
|
2017-10-06 10:14:14 -04:00
|
|
|
state_redirect_uri = redirect_uri_from_session_key(params[:state])
|
2017-10-06 08:28:40 -04:00
|
|
|
|
2017-10-06 10:14:14 -04:00
|
|
|
if state_redirect_uri
|
|
|
|
redirect_to state_redirect_uri
|
2017-09-25 03:10:25 -04:00
|
|
|
else
|
2017-10-05 08:29:22 -04:00
|
|
|
redirect_to root_path
|
2017-09-25 03:10:25 -04:00
|
|
|
end
|
|
|
|
end
|
2017-10-06 10:14:14 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def redirect_uri_from_session_key(state)
|
|
|
|
key = GoogleApi::CloudPlatform::Client
|
|
|
|
.session_key_for_redirect_uri(params[:state])
|
|
|
|
session[key] if key
|
|
|
|
end
|
2017-09-25 03:10:25 -04:00
|
|
|
end
|
|
|
|
end
|