class Rack::PrxAuth::TokenData

Attributes

scopes[R]

Public Class Methods

new(attrs = {}) click to toggle source
# 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

Public Instance Methods

authorized?(resource, namespace=nil, scope=nil) click to toggle source
# File lib/rack/prx_auth/token_data.rb, line 28
def authorized?(resource, namespace=nil, scope=nil)
  @authorized_resources.contains?(resource, namespace, scope)
end
authorized_account_ids(scope) click to toggle source
# File lib/rack/prx_auth/token_data.rb, line 36
def authorized_account_ids(scope)
  resources(::PrxAuth::Rails.configuration.namespace, scope).map(&:to_i)
end
globally_authorized?(namespace, scope=nil) click to toggle source
# 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) click to toggle source
# File lib/rack/prx_auth/token_data.rb, line 20
def resources(namespace=nil, scope=nil)
  @authorized_resources.resources(namespace, scope)
end
user_id() click to toggle source
# File lib/rack/prx_auth/token_data.rb, line 24
def user_id
  @attributes['sub']
end

Private Instance Methods

unpack_aur(aur) click to toggle source
# File lib/rack/prx_auth/token_data.rb, line 42
def unpack_aur(aur)
  return {} if aur.nil?

  aur.clone.tap do |result|
    unless result['$'].nil?
      result.delete('$').each do |role, resources|
        resources.each do |res|
          result[res.to_s] = role
        end
      end
    end
  end
end