Class: Checkpoint::Credential::Token

Inherits:
Object
  • Object
show all
Defined in:
lib/checkpoint/credential/token.rb

Overview

A Credential::Token is an identifier object for a Credential. It includes a type and an identifier. A Grant can be created for a Token. Concrete actions are resolved into a number of credentials, and those credentials’ tokens will be checked for matching grants.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, id) ⇒ Token

Create a new Credential representing a permission or instrument that represents multiple permissions.

Parameters:

  • type (String)

    the application-determined type of this credential. For example, this might be ‘permission’ or ‘role’.

  • id (String)

    the application-resolvable identifier for this credential. For example, this might be an action to be taken or the ID of a role.



21
22
23
24
# File 'lib/checkpoint/credential/token.rb', line 21

def initialize(type, id)
  @type = type.to_s
  @id = id.to_s
end

Instance Attribute Details

#idObject (readonly) Also known as: credential_id

Returns the value of attribute id.



10
11
12
# File 'lib/checkpoint/credential/token.rb', line 10

def id
  @id
end

#typeObject (readonly) Also known as: credential_type

Returns the value of attribute type.



10
11
12
# File 'lib/checkpoint/credential/token.rb', line 10

def type
  @type
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Compare with another Credential for equality. Consider them to represent the same credential if ‘other` is a credential, has the same type, and same id.

Returns:

  • (Boolean)


43
44
45
# File 'lib/checkpoint/credential/token.rb', line 43

def eql?(other)
  other.is_a?(Token) && type == other.type && id == other.id
end

#hashInteger

Returns hash code based on to_s.

Returns:

  • (Integer)

    hash code based on to_s



48
49
50
# File 'lib/checkpoint/credential/token.rb', line 48

def hash
  to_s.hash
end

#to_sString

Returns a token suitable for granting or matching this credential.

Returns:

  • (String)

    a token suitable for granting or matching this credential



37
38
39
# File 'lib/checkpoint/credential/token.rb', line 37

def to_s
  "#{type}:#{id}"
end

#tokenToken

Returns self; for convenience of taking a Credential or token.

Returns:

  • (Token)

    self; for convenience of taking a Credential or token



32
33
34
# File 'lib/checkpoint/credential/token.rb', line 32

def token
  self
end

#uriString Also known as: inspect

Returns a URI for this credential, including its type and id.

Returns:

  • (String)

    a URI for this credential, including its type and id



27
28
29
# File 'lib/checkpoint/credential/token.rb', line 27

def uri
  "credential://#{type}/#{id}"
end