Module: Oauth2Token
- Defined in:
- lib/oauth2_token.rb,
lib/oauth2_token/version.rb
Constant Summary collapse
- VERSION =
"0.1.3"
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
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, ={}) begin endpoint = get_endpoint(['uri'], "create") body = { "grant_type" => "client_credentials", "scope" => ['scope'], "realm" => ['realm'], "client_id" => client_id, "client_secret" => client_secret } 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?
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, ={}) 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 |