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

  @scopes = if attrs["scope"]
    attrs["scope"].split(" ").freeze
  else
    [].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)


36
37
38
# File 'lib/rack/prx_auth/token_data.rb', line 36

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

#authorized_account_ids(scope) ⇒ Object



44
45
46
# File 'lib/rack/prx_auth/token_data.rb', line 44

def (scope)
  resources(::PrxAuth::Rails.configuration.namespace, scope).map(&:to_i)
end

#empty_resources?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/rack/prx_auth/token_data.rb', line 57

def empty_resources?
  @authorized_resources.empty?
end

#except(*resources) ⇒ Object



53
54
55
# File 'lib/rack/prx_auth/token_data.rb', line 53

def except(*resources)
  dup.except!(*resources)
end

#except!(*resources) ⇒ Object



48
49
50
51
# File 'lib/rack/prx_auth/token_data.rb', line 48

def except!(*resources)
  @authorized_resources = @authorized_resources.except(*resources)
  self
end

#expiration_timeObject



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

def expiration_time
  @attributes["exp"]
end

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

Returns:

  • (Boolean)


40
41
42
# File 'lib/rack/prx_auth/token_data.rb', line 40

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

#issued_atObject



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

def issued_at
  @attributes["iat"]
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