Module: Auth0::Mixins::Validation

Included in:
Api::V2::Guardian, Api::V2::Roles, Api::V2::Users
Defined in:
lib/auth0/mixins/validation.rb

Overview

Module to provide validation for specific data structures.

Defined Under Namespace

Modules: Algorithm Classes: IdTokenValidator, JWTAlgorithm

Instance Method Summary collapse

Instance Method Details

#validate_permissions_array(permissions) ⇒ Object

Check a permissions array


22
23
24
25
26
27
28
29
# File 'lib/auth0/mixins/validation.rb', line 22

def validate_permissions_array(permissions)
  raise Auth0::InvalidParameter, 'Must supply an array of Permissions' unless permissions.kind_of?(Array)
  raise Auth0::MissingParameter, 'Must supply an array of Permissions' if permissions.empty?
  raise Auth0::InvalidParameter, 'All array elements must be Permissions' unless permissions.all? do |permission|
    permission.kind_of? Permission
  end
  permissions.map { |permission| permission.to_h }
end

#validate_strings_array(strings) ⇒ Object

Check a roles array


15
16
17
18
19
# File 'lib/auth0/mixins/validation.rb', line 15

def validate_strings_array(strings)
  raise Auth0::InvalidParameter, 'Must supply an array of strings' unless strings.kind_of?(Array)
  raise Auth0::MissingParameter, 'Must supply an array of strings' if strings.empty?
  raise Auth0::InvalidParameter, 'All array elements must be strings' unless strings.all? {|str| str.is_a? String}
end