Module: BWAPI::Client::OAuth

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

Instance Method Summary collapse

Instance Method Details

#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)

    User name of user

  • grant_type (String)

    Grant type of user

  • client_id (String)

    Client id

  • force_urlencoded (String)

    Force urlencoded



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/bwapi/client/oauth.rb', line 49

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

  begin
    creds = post 'oauth/token', opts
  rescue BWAPI::BWError
    return false
  else
    self.access_token = creds.access_token
    self.expires_in = creds.expires_in

    if application_client?
      self.access_token = creds.access_token
    end

    return true
  end
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)

    User name of user

  • grant_type (String)

    Grant type of user

  • client_secret (String)

    Client secret

  • client_id (String)

    Client id

  • force_urlencoded (String)

    Force urlencoded



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
# File 'lib/bwapi/client/oauth.rb', line 14

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

  begin
    creds  = post 'oauth/token', opts
  rescue BWAPI::BWError
    return false
  else
    self.access_token = creds.access_token
    self.expires_in = creds.expires_in

    if application_client?
      self.refresh_token = creds.refresh_token
    end

    return true
  end
end