Class: Grape::OAuth2::Scopes

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_oauth2/scopes.rb

Overview

OAuth2 helper for scopes validation (between requested and presented in Access Token).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scopes) ⇒ Scopes

Helper class initializer.

Parameters:

  • scopes (Array, String, #to_a)

    array, string of any object that responds to ‘to_a`



17
18
19
# File 'lib/grape_oauth2/scopes.rb', line 17

def initialize(scopes)
  @scopes = to_array(scopes || [])
end

Instance Attribute Details

#scopesArray<String> (readonly)

Array of requested scopes

Returns:

  • (Array<String>)

    scopes



10
11
12
# File 'lib/grape_oauth2/scopes.rb', line 10

def scopes
  @scopes
end

Instance Method Details

#valid_for?(access_token) ⇒ Boolean

Checks if requested scopes (passed and processed on initialization) are presented in the Access Token.

Parameters:

  • access_token (Object)

    instance of the Access Token class that responds to ‘scopes`

Returns:

  • (Boolean)

    true if requested scopes are empty or present in access token scopes and false in other cases



31
32
33
# File 'lib/grape_oauth2/scopes.rb', line 31

def valid_for?(access_token)
  scopes.empty? || present_in?(access_token.scopes)
end