summaryrefslogtreecommitdiff
path: root/app/controllers/google_api/authorizations_controller.rb
blob: 709d1d34796b990c8dcfe4b4621b8a20828bf375 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
module GoogleApi
  class AuthorizationsController < ApplicationController
    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

      key, _ = GoogleApi::CloudPlatform::Client
        .session_key_for_second_redirect_uri(secure: params[:state])

      second_redirect_uri = session[key]

      if second_redirect_uri.present?
        redirect_to second_redirect_uri
      else
        redirect_to root_path
      end
    end
  end
end