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.



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

def initialize(attrs = {})
  @attributes = attrs

  @authorized_resources = ::PrxAuth::ResourceMap.new(unpack_aur(attrs['aur'])).freeze
  
  if attrs['scope']
    @scopes = attrs['scope'].split(' ').freeze
  else
    @scopes = [].freeze
  end
end

Instance Attribute Details

#scopesObject (readonly)

Returns the value of attribute scopes.



6
7
8
# File 'lib/rack/prx_auth/token_data.rb', line 6

def scopes
  @scopes
end

Instance Method Details

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

Returns:

  • (Boolean)


28
29
30
# File 'lib/rack/prx_auth/token_data.rb', line 28

def authorized?(resource, namespace=nil, scope=nil)
  @authorized_resources.contains?(resource, namespace, scope)
end

#globally_authorized?(namespace, scope = nil) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/rack/prx_auth/token_data.rb', line 32

def globally_authorized?(namespace, scope=nil)
  authorized?(::PrxAuth::ResourceMap::WILDCARD_KEY, namespace, scope)
end

#resources(namespace = nil, scope = nil) ⇒ Object



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

def resources(namespace=nil, scope=nil)
  @authorized_resources.resources(namespace, scope)
end

#user_idObject



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

def user_id
  @attributes['sub']
end