summaryrefslogtreecommitdiff
path: root/app/controllers/google_api/authorizations_controller.rb
blob: 79f49d598af3978aeb7bf554d2d39656fa991b47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
module GoogleApi
  class AuthorizationsController < ApplicationController
    def callback
      token, expires_at = GoogleApi::CloudPlatform::Client
        .new(nil, callback_google_api_authorizations_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

      if params[:state].present?
        redirect_to params[:state]
      else
        redirect_to root_path
      end
    end
  end
end