Module: SignIn::AudienceValidator

Extended by:
ActiveSupport::Concern
Included in:
AuthenticationAndSSOConcerns
Defined in:
app/controllers/concerns/sign_in/audience_validator.rb

Instance Method Summary collapse

Instance Method Details

#authenticateObject (protected)



22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/concerns/sign_in/audience_validator.rb', line 22

def authenticate
  validate_audience!
  super
rescue Errors::InvalidAudienceError => e
  render json: { errors: e }, status: :unauthorized
rescue Errors::AccessTokenExpiredError => e
  render json: { errors: e }, status: :forbidden
rescue Errors::StandardError => e
  handle_authenticate_error(e)
end

#validate_audience!Object (private)



35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/concerns/sign_in/audience_validator.rb', line 35

def validate_audience!
  valid_audience = self.class.valid_audience

  return if valid_audience.blank?
  return if access_token.audience.any? { |aud| valid_audience.include?(aud) }

  Rails.logger.error('[SignIn][AudienceValidator] Invalid audience',
                     { invalid_audience: access_token.audience, valid_audience: })
  raise Errors::InvalidAudienceError.new(message: 'Invalid audience')
end