Class: Firebase::Auth::Token
- Inherits:
-
Object
- Object
- Firebase::Auth::Token
- Defined in:
- lib/firebase/auth/token.rb
Instance Attribute Summary collapse
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #entity_for(entity_class) ⇒ Object
-
#initialize(payload: {}, token: nil, verify_options: {}) ⇒ Token
constructor
A new instance of Token.
- #set_public_key ⇒ Object
Constructor Details
#initialize(payload: {}, token: nil, verify_options: {}) ⇒ Token
Returns a new instance of Token.
7 8 9 10 11 12 13 |
# File 'lib/firebase/auth/token.rb', line 7 def initialize(payload: {}, token: nil, verify_options: {}) set_public_key @token = token @payload = FirebaseIdToken::Signature.verify(token) # user not found or decode error raise StandardError, 'decode error' if @payload.nil? end |
Instance Attribute Details
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/firebase/auth/token.rb', line 5 def payload @payload end |
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/firebase/auth/token.rb', line 4 def token @token end |
Instance Method Details
#entity_for(entity_class) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/firebase/auth/token.rb', line 15 def entity_for(entity_class) if entity_class.respond_to? :from_token_payload entity_class.from_token_payload @payload else # FIXME: error handling entity_class.find_by!(uid: @payload['sub']) end end |
#set_public_key ⇒ Object
24 25 26 27 28 29 |
# File 'lib/firebase/auth/token.rb', line 24 def set_public_key # FIXME: cache return unless FirebaseIdToken::Certificates.blank? || 0 <= FirebaseIdToken::Certificates.ttl FirebaseIdToken::Certificates.request nil end |