Class: Authorization
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Authorization
- Defined in:
- app/models/authorization.rb
Class Method Summary collapse
Instance Method Summary collapse
- #access_token ⇒ Object
- #authorize_url(params = {}) ⇒ Object
- #expired? ⇒ Boolean
- #get_access_token!(code) ⇒ Object
- #granted? ⇒ Boolean
- #refresh! ⇒ Object
Class Method Details
.[](name) ⇒ Object
7 8 9 |
# File 'app/models/authorization.rb', line 7 def self.[](name) find_by(name: name) end |
.set_access_token!(params) ⇒ Object
11 12 13 14 15 |
# File 'app/models/authorization.rb', line 11 def self.set_access_token!(params) Authorization.find(params.fetch(:state)).tap do || .get_access_token! params.fetch(:code) end end |
Instance Method Details
#access_token ⇒ Object
33 34 35 36 |
# File 'app/models/authorization.rb', line 33 def access_token refresh! if expired? super end |
#authorize_url(params = {}) ⇒ Object
21 22 23 |
# File 'app/models/authorization.rb', line 21 def (params={}) provider. params.merge(scope: scope, state: id) end |
#expired? ⇒ Boolean
38 39 40 41 |
# File 'app/models/authorization.rb', line 38 def expired? return false unless granted? Time.now >= expires_at end |
#get_access_token!(code) ⇒ Object
29 30 31 |
# File 'app/models/authorization.rb', line 29 def get_access_token!(code) merge! provider.redeem_access_token(code) end |
#granted? ⇒ Boolean
17 18 19 |
# File 'app/models/authorization.rb', line 17 def granted? expires_in.present? end |
#refresh! ⇒ Object
25 26 27 |
# File 'app/models/authorization.rb', line 25 def refresh! merge! provider.refresh_access_token(self) end |