Module: Devbootcamp::OAuth
- Defined in:
- lib/devbootcamp/oauth.rb
Class Method Summary collapse
- .authorize!(oauth_code, options = {}) ⇒ Object
- .authorize_url(params = {}) ⇒ Object
- .authorized? ⇒ Boolean
- .client ⇒ Object
- .refresh! ⇒ Object
- .site_uri ⇒ Object
- .token_as_hash ⇒ Object
- .token_from_hash(hash) ⇒ Object
- .unauthorize_url(params = {}) ⇒ Object
Class Method Details
.authorize!(oauth_code, options = {}) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/devbootcamp/oauth.rb', line 56 def (oauth_code, = {}) @token = client.auth_code.get_token(oauth_code, :redirect_uri => .fetch(:redirect_uri, callback_url) ) end |
.authorize_url(params = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/devbootcamp/oauth.rb', line 24 def (params={}) params[:redirect_uri] ||= callback_url raise "redirect_uri cannot be blank" if params[:redirect_uri].blank? client.auth_code.(params) end |
.authorized? ⇒ Boolean
52 53 54 |
# File 'lib/devbootcamp/oauth.rb', line 52 def !!token end |
.client ⇒ Object
14 15 16 17 18 |
# File 'lib/devbootcamp/oauth.rb', line 14 def client @client ||= OAuth2::Client.new( application_id, secret, site: site ) end |
.refresh! ⇒ Object
63 64 65 |
# File 'lib/devbootcamp/oauth.rb', line 63 def refresh! self.token = token.refresh! if token && token.refresh_token end |
.site_uri ⇒ Object
20 21 22 |
# File 'lib/devbootcamp/oauth.rb', line 20 def site_uri URI(client.site) end |
.token_as_hash ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/devbootcamp/oauth.rb', line 39 def token_as_hash { token: token.token, refresh_token: token.refresh_token, expires_at: token.expires_at, } end |
.token_from_hash(hash) ⇒ Object
47 48 49 50 |
# File 'lib/devbootcamp/oauth.rb', line 47 def token_from_hash(hash) return unless hash @token = OAuth2::AccessToken.new(client, hash[:token], hash) end |
.unauthorize_url(params = {}) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/devbootcamp/oauth.rb', line 30 def (params={}) params[:redirect_uri] ||= callback_url raise "redirect_uri cannot be blank" if params[:redirect_uri].blank? site_uri.tap do |uri| uri.path = '/unauthenticate' uri.query = params.to_param end.to_s end |