summaryrefslogtreecommitdiff
path: root/app/controllers/google_api/authorizations_controller.rb
blob: e99c38025b82f3791985a266612fbe0b10993b2b (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
25
26
27
module GoogleApi
  class AuthorizationsController < ApplicationController
    # callback_google_api_authorizations GET|POST /google_api/authorizations/callback(.:format)                                                        google_api/authorizations#callback
    ##
    # TODO: 
    # - Is it ok to use both "http://localhost:3000/google_api/authorizations/callback"(For login) and "http://localhost:3000/google_api/authorizations/callback"(For API token)
    def callback
      session[access_token_key] = api_client.get_token(params[:code])

      if params[:state]
        redirect_to params[:state]
      else
        redirect_to root_url
      end
    end

    def api_client
      @api_client ||=
        GoogleApi::Authentication.new(nil, callback_google_api_authorizations_url)
    end

    def access_token_key
      # :"#{api_client.scope}_access_token"
      :"hoge_access_token" # TODO: 
    end
  end
end