Module: Oauth2Token
- Defined in:
- lib/oauth2_token.rb,
lib/oauth2_token/version.rb
Constant Summary collapse
- VERSION =
"0.1.4"
Class Method Summary collapse
- .get_token(client_id, client_secret, options = {}) ⇒ Object
- .is_token_active?(token, options = {}) ⇒ Boolean (also: is_token_valid?)
Class Method Details
.get_token(client_id, client_secret, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oauth2_token.rb', line 9 def get_token(client_id, client_secret, ={}) begin endpoint = get_endpoint(['uri'], "create") jwt = create_jwt(client_id, client_secret, endpoint, ['realm']) body = { "grant_type" => "client_credentials", "scope" => ['scope'], "realm" => ['realm'], "client_assertion_type" => "urn:ietf:params:oauth:client-assertion-type:jwt-bearer", "client_assertion" => jwt } response = wrap(HTTParty.post(endpoint, .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?
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/oauth2_token.rb', line 27 def is_token_active?(token, ={}) begin endpoint = get_endpoint(['uri'], "validate") body = { "token" => token, "realm" => ['realm'] } response = wrap(HTTParty.post(endpoint, .merge(:body => body))) response['active'] rescue Exception => e raise "Unable to validate token. #{e.backtrace}" end end |