class G5AuthenticatableApi::Services::TokenValidator

Validates an access token against the G5 Auth server

Attributes

error[R]

Public Instance Methods

auth_response_header() click to toggle source
# File lib/g5_authenticatable_api/services/token_validator.rb, line 24
def auth_response_header
  return unless error

  auth_header = String.new('Bearer')

  if access_token
    auth_header << " error=\"#{error_code}\""

    if error_description.present?
      auth_header << ",error_description=\"#{error_description}\""
    end
  end

  auth_header
end
valid?() click to toggle source
# File lib/g5_authenticatable_api/services/token_validator.rb, line 17
def valid?
  validate!
  true
rescue StandardError
  false
end
validate!() click to toggle source
# File lib/g5_authenticatable_api/services/token_validator.rb, line 11
def validate!
  token_data unless skip_validation?
rescue StandardError => @error
  raise error
end

Private Instance Methods

error_code() click to toggle source
# File lib/g5_authenticatable_api/services/token_validator.rb, line 42
def error_code
  error_code = error.code if error.respond_to?(:code)
  error_code || 'invalid_request'
end
error_description() click to toggle source
# File lib/g5_authenticatable_api/services/token_validator.rb, line 47
def error_description
  return unless error.respond_to?(:description)
  error.description
end
skip_validation?() click to toggle source
# File lib/g5_authenticatable_api/services/token_validator.rb, line 52
def skip_validation?
  @warden.try(:user) && !G5AuthenticatableApi.strict_token_validation
end