Class: Firebase::Auth
- Inherits:
-
Object
- Object
- Firebase::Auth
- Defined in:
- lib/firebase-ruby/auth.rb
Constant Summary collapse
- GOOGLE_JWT_SCOPE =
'https://www.googleapis.com/auth/firebase.database https://www.googleapis.com/auth/userinfo.email'
- GOOGLE_JWT_AUD =
'https://oauth2.googleapis.com/token'
- GOOGLE_ALGORITHM =
'RS256'
- GOOGLE_GRANT_TYPE =
'urn:ietf:params:oauth:grant-type:jwt-bearer'
- GOOGLE_TOKEN_URL =
'https://oauth2.googleapis.com/token'
Instance Attribute Summary collapse
-
#access_token ⇒ Object
readonly
Returns the value of attribute access_token.
-
#client_email ⇒ Object
readonly
Returns the value of attribute client_email.
-
#expires ⇒ Object
readonly
Returns the value of attribute expires.
-
#project_id ⇒ Object
readonly
Returns the value of attribute project_id.
-
#token_uri ⇒ Object
readonly
Returns the value of attribute token_uri.
Instance Method Summary collapse
-
#expired? ⇒ Boolean
If token has already expired.
-
#expiring? ⇒ Boolean
If token is expiring within a minute.
-
#initialize(json: nil, path: nil) ⇒ Auth
constructor
Creates Firebase OAuth based auth object; one argument must be specified.
-
#valid_token ⇒ Object
Return a valid access token; it will retrieve a new token if necessary.
Constructor Details
#initialize(json: nil, path: nil) ⇒ Auth
Creates Firebase OAuth based auth object; one argument must be specified
20 21 22 23 24 25 26 |
# File 'lib/firebase-ruby/auth.rb', line 20 def initialize(json: nil, path: nil) if json load_privatekeyjson(json) elsif path load_privatekeyfile(path) end end |
Instance Attribute Details
#access_token ⇒ Object (readonly)
Returns the value of attribute access_token.
16 17 18 |
# File 'lib/firebase-ruby/auth.rb', line 16 def access_token @access_token end |
#client_email ⇒ Object (readonly)
Returns the value of attribute client_email.
14 15 16 |
# File 'lib/firebase-ruby/auth.rb', line 14 def client_email @client_email end |
#expires ⇒ Object (readonly)
Returns the value of attribute expires.
17 18 19 |
# File 'lib/firebase-ruby/auth.rb', line 17 def expires @expires end |
#project_id ⇒ Object (readonly)
Returns the value of attribute project_id.
13 14 15 |
# File 'lib/firebase-ruby/auth.rb', line 13 def project_id @project_id end |
#token_uri ⇒ Object (readonly)
Returns the value of attribute token_uri.
15 16 17 |
# File 'lib/firebase-ruby/auth.rb', line 15 def token_uri @token_uri end |
Instance Method Details
#expired? ⇒ Boolean
If token has already expired
42 43 44 45 |
# File 'lib/firebase-ruby/auth.rb', line 42 def expired? return true if expires - Time.now <= 0 return false end |
#expiring? ⇒ Boolean
If token is expiring within a minute
36 37 38 39 |
# File 'lib/firebase-ruby/auth.rb', line 36 def expiring? return true if expires - Time.now < 60 return false end |
#valid_token ⇒ Object
Return a valid access token; it will retrieve a new token if necessary
29 30 31 32 33 |
# File 'lib/firebase-ruby/auth.rb', line 29 def valid_token return access_token if access_token && !expiring? return access_token if request_access_token raise 'No valid access token.' end |