Module: BWAPI::Client::OAuth

Included in:
BWAPI::Client
Defined in:
lib/bwapi/client/oauth.rb

Overview

OAuth module for oauth/token endpoint

Instance Method Summary collapse

Instance Method Details

#determine_grant_type ⇒ String

Determines grant-type used for client

Returns:

  • (String) —

    relevant grant type for client



55
56
57
58
# File 'lib/bwapi/client/oauth.rb', line 55

def determine_grant_type
  return grant_type unless grant_type.nil?
  api_client? ? 'api-password' : 'password'
end

#oauth_refresh_token(opts = {}) ⇒ Object Also known as: refresh

Refresh a authenticated users oauth_token

Parameters:

  • opts (Hash) (defaults to: {}) —

    options hash of parameters

Options Hash (opts):

  • username (String) —

    User name of user

  • password (String) —

    Password of the user

  • grant_type (String) —

    Grant type of user

  • refresh_token (String) —

    Users refresh token

  • client_id (String) —

    Client id

  • force_urlencoded (String) —

    Force urlencoded



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/bwapi/client/oauth.rb', line 38

def oauth_refresh_token opts={}
  opts = {
    username: username,
    password: password,
    refresh_token: refresh_token,
    grant_type: 'refresh_token',
    client_id: client_id,
    force_urlencoded: true
  }.merge opts

  oauth_request opts
end

#oauth_request(opts = {}) ⇒ Object

Sends a oauth request

Parameters:

  • opts (Hash) (defaults to: {}) —

    options hash of parameters



63
64
65
66
67
68
69
# File 'lib/bwapi/client/oauth.rb', line 63

def oauth_request opts={}
  creds = post 'oauth/token', opts
  self.access_token  = creds.access_token
  self.expires_in    = creds.expires_in
  self.refresh_token = creds.refresh_token if application_client?
  creds
end

#oauth_token(opts = {}) ⇒ Object Also known as: login

Authenticate a user

Parameters:

  • opts (Hash) (defaults to: {}) —

    options hash of parameters

Options Hash (opts):

  • username (String) —

    User name of user

  • password (String) —

    Password of the user

  • grant_type (String) —

    Grant type of user

  • client_secret (String) —

    Client secret

  • client_id (String) —

    Client id

  • force_urlencoded (String) —

    Force urlencoded



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/bwapi/client/oauth.rb', line 15

def oauth_token opts={}
  opts = {
    username: username,
    password: password,
    grant_type: determine_grant_type,
    client_secret: client_secret,
    client_id: client_id,
    force_urlencoded: true
  }.merge opts

  oauth_request opts
end