Class: Rack::PrxAuth::TokenData
- Inherits:
-
Object
- Object
- Rack::PrxAuth::TokenData
- Defined in:
- lib/rack/prx_auth/token_data.rb
Instance Attribute Summary collapse
-
#scopes ⇒ Object
readonly
Returns the value of attribute scopes.
Instance Method Summary collapse
- #authorized?(resource, namespace = nil, scope = nil) ⇒ Boolean
- #authorized_account_ids(scope) ⇒ Object
- #empty_resources? ⇒ Boolean
- #except(*resources) ⇒ Object
- #except!(*resources) ⇒ Object
- #expiration_time ⇒ Object
- #globally_authorized?(namespace, scope = nil) ⇒ Boolean
-
#initialize(attrs = {}) ⇒ TokenData
constructor
A new instance of TokenData.
- #issued_at ⇒ Object
- #resources(namespace = nil, scope = nil) ⇒ Object
- #user_id ⇒ Object
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
#scopes ⇒ Object (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
36 37 38 |
# File 'lib/rack/prx_auth/token_data.rb', line 36 def (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
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_time ⇒ Object
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
40 41 42 |
# File 'lib/rack/prx_auth/token_data.rb', line 40 def (namespace, scope = nil) (::PrxAuth::ResourceMap::WILDCARD_KEY, namespace, scope) end |
#issued_at ⇒ Object
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_id ⇒ Object
24 25 26 |
# File 'lib/rack/prx_auth/token_data.rb', line 24 def user_id @attributes["sub"] end |