module Devbootcamp::OAuth

Public Class Methods

authorize!(oauth_code, options = {}) click to toggle source
# File lib/devbootcamp/oauth.rb, line 56
def authorize!(oauth_code, options = {})
  @token = client.auth_code.get_token(oauth_code,
    :redirect_uri => options.fetch(:redirect_uri, callback_url)
  )
  authorized?
end
authorize_url(params={}) click to toggle source
# File lib/devbootcamp/oauth.rb, line 24
def authorize_url(params={})
  params[:redirect_uri] ||= callback_url
  raise "redirect_uri cannot be blank" if params[:redirect_uri].blank?
  client.auth_code.authorize_url(params)
end
authorized?() click to toggle source
# File lib/devbootcamp/oauth.rb, line 52
def authorized?
  !!token
end
client() click to toggle source
# File lib/devbootcamp/oauth.rb, line 14
def client
  @client ||= OAuth2::Client.new(
    application_id, secret, site: site
  )
end
refresh!() click to toggle source
# File lib/devbootcamp/oauth.rb, line 63
def refresh!
  self.token = token.refresh! if token && token.refresh_token
end
site_uri() click to toggle source
# File lib/devbootcamp/oauth.rb, line 20
def site_uri
  URI(client.site)
end
token_as_hash() click to toggle source
# 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) click to toggle source
# 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={}) click to toggle source
# File lib/devbootcamp/oauth.rb, line 30
def unauthorize_url(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