Class: GoogleAuthBox::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_auth_box/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id_hash:, scopes:, data_file_path:, base_uri:) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/google_auth_box/client.rb', line 5

def initialize(client_id_hash:, scopes:, data_file_path:, base_uri:)
  @base_uri = base_uri

  client_id = Google::Auth::ClientId.from_hash client_id_hash
  f = File.open data_file_path
  data_path = File.absolute_path f
  token_store = Google::Auth::Stores::FileTokenStore.new(
    :file => data_path
  )

  f.close

  @auth_client = Google::Auth::UserAuthorizer.new(
    client_id,
    scopes,
    token_store,
    base_uri
  )

  def get_auth_url
    @auth_client.get_authorization_url(base_url: @base_uri)
  end

  def get_creds(id)
    @auth_client.get_credentials(id)
  end

  def save_creds(id, code)
    @auth_client.get_and_store_credentials_from_code(
      user_id: id,
      code: code,
      base_url: @base_uri
    )
  end
end

Instance Method Details

#get_auth_urlObject



24
25
26
# File 'lib/google_auth_box/client.rb', line 24

def get_auth_url
  @auth_client.get_authorization_url(base_url: @base_uri)
end

#get_creds(id) ⇒ Object



28
29
30
# File 'lib/google_auth_box/client.rb', line 28

def get_creds(id)
  @auth_client.get_credentials(id)
end

#save_creds(id, code) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/google_auth_box/client.rb', line 32

def save_creds(id, code)
  @auth_client.get_and_store_credentials_from_code(
    user_id: id,
    code: code,
    base_url: @base_uri
  )
end