Class: Minato::Rails::Auth::User

Inherits:
Object
  • Object
show all
Defined in:
lib/minato/rails/auth/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token_payload) ⇒ User

Returns a new instance of User.



11
12
13
14
# File 'lib/minato/rails/auth/user.rb', line 11

def initialize(token_payload)
  @token_payload_raw = token_payload
  @token_payload_obj = ObjectHash.new(token_payload)
end

Instance Attribute Details

#token_payload_objObject (readonly)

Returns the value of attribute token_payload_obj.



9
10
11
# File 'lib/minato/rails/auth/user.rb', line 9

def token_payload_obj
  @token_payload_obj
end

#token_payload_rawObject (readonly)

Returns the value of attribute token_payload_raw.



9
10
11
# File 'lib/minato/rails/auth/user.rb', line 9

def token_payload_raw
  @token_payload_raw
end

Instance Method Details

#auth_password?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/minato/rails/auth/user.rb', line 28

def auth_password?
  authentication_method? 'password'
end

#auth_providerObject



32
33
34
35
36
# File 'lib/minato/rails/auth/user.rb', line 32

def auth_provider
  return unless auth_sso?

  authentication_method('oidc')['provider']
end

#auth_sso?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/minato/rails/auth/user.rb', line 24

def auth_sso?
  authentication_method? 'oidc'
end

#human?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/minato/rails/auth/user.rb', line 16

def human?
  session_obj&.identity.present?
end

#identityObject



38
39
40
41
42
43
44
# File 'lib/minato/rails/auth/user.rb', line 38

def identity
  return nil if machine?

  return impersonator_identity unless impersonated?

  session_obj.identity..impersonated_identity
end

#impersonated?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
# File 'lib/minato/rails/auth/user.rb', line 54

def impersonated?
  return false if machine?

  session_obj.identity.&.impersonated_identity.present?
end

#impersonator_identityObject



46
47
48
# File 'lib/minato/rails/auth/user.rb', line 46

def impersonator_identity
  session_obj.identity
end

#machine?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/minato/rails/auth/user.rb', line 20

def machine?
  !human?
end

#subjectObject



50
51
52
# File 'lib/minato/rails/auth/user.rb', line 50

def subject
  @token_payload_obj.sub
end