Class: TokenValidation::V2::Client
- Inherits:
-
Common::Client::Base
- Object
- Common::Client::Base
- TokenValidation::V2::Client
- Defined in:
- lib/token_validation/v2/client.rb
Instance Method Summary collapse
-
#initialize(api_key:) ⇒ Client
constructor
A new instance of Client.
- #token_valid?(audience:, token:, scope:) ⇒ Boolean
Methods inherited from Common::Client::Base
configuration, #raise_backend_exception
Methods included from SentryLogging
#log_exception_to_sentry, #log_message_to_sentry, #non_nil_hash?, #normalize_level, #rails_logger
Constructor Details
#initialize(api_key:) ⇒ Client
Returns a new instance of Client.
11 12 13 |
# File 'lib/token_validation/v2/client.rb', line 11 def initialize(api_key:) @api_key = api_key end |
Instance Method Details
#token_valid?(audience:, token:, scope:) ⇒ Boolean
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/token_validation/v2/client.rb', line 15 def token_valid?(audience:, token:, scope:) json = URI.encode_www_form({ 'aud': audience }) headers = { 'apiKey': @api_key, 'Authorization': "Bearer #{token}", 'Content-Type': 'application/x-www-form-urlencoded' } response = perform(:post, 'v2/validation', json, headers) return false unless response.status == 200 token_permits_scope?(scope:, response:) end |