Class: Rack::PrxAuth::TokenData

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/prx_auth/token_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ TokenData

Returns a new instance of TokenData.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rack/prx_auth/token_data.rb', line 6

def initialize(attrs = {})
  @attributes = attrs
  if attrs['aur']
    @authorized_resources = unpack_aur(attrs['aur']).freeze
  else
    @authorized_resources = {}.freeze
  end
  if attrs['scope']
    @scopes = attrs['scope'].split(' ').freeze
  else
    @scopes = [].freeze
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



4
5
6
# File 'lib/rack/prx_auth/token_data.rb', line 4

def attributes
  @attributes
end

#authorized_resourcesObject (readonly)

Returns the value of attribute authorized_resources.



4
5
6
# File 'lib/rack/prx_auth/token_data.rb', line 4

def authorized_resources
  @authorized_resources
end

#scopesObject (readonly)

Returns the value of attribute scopes.



4
5
6
# File 'lib/rack/prx_auth/token_data.rb', line 4

def scopes
  @scopes
end

Instance Method Details

#authorized?(resource, scope = nil) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/rack/prx_auth/token_data.rb', line 24

def authorized?(resource, scope=nil)
  if auth = authorized_resources[resource.to_s]
    scope.nil? || (scopes + auth.split(' ')).include?(scope.to_s)
  end
end

#user_idObject



20
21
22
# File 'lib/rack/prx_auth/token_data.rb', line 20

def user_id
  @attributes['sub']
end