Module: Panoptes::Client::Authentication
- Extended by:
- Gem::Deprecate
- Included in:
- Panoptes::Client
- Defined in:
- lib/panoptes/client/authentication.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
Instance Method Summary collapse
- #authenticated? ⇒ Boolean
- #authenticated_admin? ⇒ Boolean
- #authenticated_user_display_name ⇒ Object
- #authenticated_user_id ⇒ Object
- #authenticated_user_login ⇒ Object
- #jwt_payload ⇒ Object
- #token_contents ⇒ Object
- #token_expiry ⇒ Object
Instance Attribute Details
#payload ⇒ Object (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
34 35 36 |
# File 'lib/panoptes/client/authentication.rb', line 34 def authenticated? !!token_contents['id'] end |
#authenticated_admin? ⇒ 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_name ⇒ Object
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_id ⇒ Object
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_login ⇒ Object
38 39 40 41 |
# File 'lib/panoptes/client/authentication.rb', line 38 def authenticated_user_login ensure_authenticated token_contents.fetch('login', nil) end |
#jwt_payload ⇒ Object
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_contents ⇒ Object
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_expiry ⇒ Object
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 |