Class: ADAL::UserIdentifier

Inherits:
Object
  • Object
show all
Includes:
Type
Defined in:
lib/adal/user_identifier.rb

Overview

Identifier for users in the cache.

Ideally, the application will first use a different OAuth flow, such as the Authorization Code flow, to acquire an ADAL::SuccessResponse. Then, it can create ADAL::UserIdentifier to query the cache which will refresh tokens as necessary.

Defined Under Namespace

Modules: Type

Constant Summary

Constants included from Type

Type::DISPLAYABLE_ID, Type::UNIQUE_ID

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, type) ⇒ Object

Creates a UserIdentifier with a specific type. Used for cache lookups. Matches .NET ADAL implementation.

Parameters:

  • String

    id

  • UserIdentifier::Type


49
50
51
52
53
54
55
# File 'lib/adal/user_identifier.rb', line 49

def initialize(id, type)
  unless [UNIQUE_ID, DISPLAYABLE_ID].include? type
    fail ArgumentError, 'type must be an ADAL::UserIdentifier::Type.'
  end
  @id = id
  @type = type
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



31
32
33
# File 'lib/adal/user_identifier.rb', line 31

def id
  @id
end

#typeObject (readonly)

Returns the value of attribute type.



32
33
34
# File 'lib/adal/user_identifier.rb', line 32

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object

Overrides comparison operator for cache lookups

Parameters:

  • UserIdentifier

    other

Returns:

  • Boolean



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/adal/user_identifier.rb', line 71

def ==(other)
  case other
  when UserIdentifier
    self.equal? other
  when UserInformation
    (type == UNIQUE_ID && id == other.unique_id) ||
      (type == DISPLAYABLE_ID && id == other.displayable_id)
  when String
    @id == other
  end
end

#request_paramsObject

These parameters should only be used for cache lookup. This is enforced by ADAL::TokenRequest.

Returns:

  • Hash



62
63
64
# File 'lib/adal/user_identifier.rb', line 62

def request_params
  { user_info: self }
end