Module: Oauth2Token

Defined in:
lib/oauth2_token.rb,
lib/oauth2_token/version.rb

Constant Summary collapse

VERSION =
"0.1.3"

Class Method Summary collapse

Class Method Details

.get_token(client_id, client_secret, options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/oauth2_token.rb', line 8

def get_token(client_id, client_secret, options={})
  begin
    endpoint = get_endpoint(options['uri'], "create")
    body = {
      "grant_type" => "client_credentials",
      "scope" => options['scope'],
      "realm" => options['realm'],
      "client_id" => client_id,
      "client_secret" => client_secret
    }
    response = wrap(HTTParty.post(endpoint, http_options.merge(:body => body)))
    response['access_token']
  rescue Exception => e
    raise e, "unable to fetch token for #{client_id}"
  end
end

.is_token_active?(token, options = {}) ⇒ Boolean Also known as: is_token_valid?

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oauth2_token.rb', line 25

def is_token_active?(token, options={})
  begin
    endpoint = get_endpoint(options['uri'], "validate")
    body = {
      "token" => token,
      "realm" => options['realm']
    }
    response = wrap(HTTParty.post(endpoint, http_options.merge(:body => body)))
    response['active']
  rescue Exception => e
    raise "Unable to validate token. #{e.backtrace}"
  end
end