Module: Bearcat::Client::OAuth2

Included in:
Bearcat::Client
Defined in:
lib/bearcat/client/o_auth2.rb

Instance Method Summary collapse

Instance Method Details

#auth_redirect_url(client_id, redirect_uri, scopes = nil, response_type = 'code') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bearcat/client/o_auth2.rb', line 5

def auth_redirect_url(client_id, redirect_uri, scopes = nil, response_type='code')
  fullpath('login/oauth2/auth')
  uri = URI.parse(fullpath('login/oauth2/auth'))
  query = [
    ['client_id', client_id],
    ['redirect_uri', redirect_uri],
    ['response_type', response_type]
  ]
  query << ['scopes', scopes] if scopes
  uri.query = URI.encode_www_form(query)
  uri.to_s
end

#retrieve_token(client_id, redirect_url, client_secret, code) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/bearcat/client/o_auth2.rb', line 18

def retrieve_token(client_id, redirect_url, client_secret, code)
  body = post('/login/oauth2/token', {
    client_id: client_id,
    redirect_url: redirect_url,
    client_secret: client_secret,
    code: code
  })
  config[:token] = body['access_token']
  set_connection(config)
  config[:token]
end