2018-12-05 23:21:45 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module GoogleApi
|
|
|
|
class AuthorizationsController < ApplicationController
|
2019-03-13 22:55:13 +05:30
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
before_action :validate_session_key!
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
def callback
|
|
|
|
token, expires_at = GoogleApi::CloudPlatform::Client
|
|
|
|
.new(nil, callback_google_api_auth_url)
|
|
|
|
.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
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
redirect_to redirect_uri_from_session
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-03-13 22:55:13 +05:30
|
|
|
def validate_session_key!
|
|
|
|
access_denied! unless redirect_uri_from_session.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_uri_from_session
|
|
|
|
strong_memoize(:redirect_uri_from_session) do
|
|
|
|
if params[:state].present?
|
|
|
|
session[session_key_for_redirect_uri(params[:state])]
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_key_for_redirect_uri(state)
|
|
|
|
GoogleApi::CloudPlatform::Client.session_key_for_redirect_uri(state)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|