Module: Panoptes::Client::Authentication

Extended by:
Gem::Deprecate
Included in:
Panoptes::Client
Defined in:
lib/panoptes/client/authentication.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



10
11
12
# File 'lib/panoptes/client/authentication.rb', line 10

def payload
  @payload
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/panoptes/client/authentication.rb', line 34

def authenticated?
  !!token_contents['id']
end

#authenticated_admin?Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/panoptes/client/authentication.rb', line 53

def authenticated_admin?
  ensure_authenticated
  token_contents.fetch('admin', false)
end

#authenticated_user_display_nameObject



43
44
45
46
# File 'lib/panoptes/client/authentication.rb', line 43

def authenticated_user_display_name
  ensure_authenticated
  token_contents.fetch('dname', nil)
end

#authenticated_user_idObject



48
49
50
51
# File 'lib/panoptes/client/authentication.rb', line 48

def authenticated_user_id
  ensure_authenticated
  token_contents.fetch('id')
end

#authenticated_user_loginObject



38
39
40
41
# File 'lib/panoptes/client/authentication.rb', line 38

def 
  ensure_authenticated
  token_contents.fetch('login', nil)
end

#jwt_payloadObject



12
13
14
15
16
17
# File 'lib/panoptes/client/authentication.rb', line 12

def jwt_payload
  raise NotLoggedIn unless @auth[:token]
  @payload = decode_token(@auth[:token])
rescue JWT::ExpiredSignature
  raise AuthenticationExpired
end

#token_contentsObject



19
20
21
22
23
24
25
26
27
# File 'lib/panoptes/client/authentication.rb', line 19

def token_contents
  if payload_exists? && !payload_expired?
    # use the cached version of the payload while not expired
    payload['data']
  else
    # decode the payload from the JWT token
    jwt_payload['data']
  end
end

#token_expiryObject



29
30
31
32
# File 'lib/panoptes/client/authentication.rb', line 29

def token_expiry
  # always decode and fetch the expiry time from the JWT token
  Time.at(jwt_payload.fetch('exp',0)).utc
end