Class: EdmentumClient::Authentication

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

Class Method Summary collapse

Class Method Details

.token(config) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/edmentum_client.rb', line 91

def self.token(config)
  url = "https://auth.edmentum.com/connect/token"
  req_opts = {
    method: :post,
    headers: {
      "Authorization": "#{config.basic_auth_token}",
      "Content-Type": "application/x-www-form-urlencoded"
    },
    body: {
      grant_type: "password",
      username: config.username,
      password: config.password,
      scope: "openid profile offline_access role api_web"
    }
  }

  request = Typhoeus::Request.new(url, req_opts)
  response = request.run
  if response.success?
    "Bearer " + JSON.parse(response.body)["access_token"]
  else
    raise "Authentication failed"
  end

end