class Plangrade::OAuth2Client

Constants

AUTHORIZE_PATH
SITE_URL
TOKEN_PATH

Public Class Methods

new(client_id, client_secret, opts={}) { |self| ... } click to toggle source
Calls superclass method
# File lib/plangrade/oauth2_client.rb, line 10
def initialize(client_id, client_secret, opts={})
  site_url = opts.delete(:site_url) || SITE_URL
  opts[:token_path]     ||= TOKEN_PATH
  opts[:authorize_path] ||= AUTHORIZE_PATH
  super(site_url, client_id, client_secret, opts)
  yield self if block_given?
  self
end

Public Instance Methods

exchange_auth_code_for_token(opts={}) click to toggle source

client_id={client_id}&code=G3Y6jU3a&grant_type=authorization_code& redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&client_secret={client_secret}

# File lib/plangrade/oauth2_client.rb, line 57
def exchange_auth_code_for_token(opts={})
  unless (opts[:params] && opts[:params][:code])
    raise ArgumentError.new("You must include an authorization code as a parameter")
  end
  opts[:authenticate] ||= :body
  code = opts[:params].delete(:code)
  authorization_code.get_token(code, opts)
end
refresh!(token, opts={}) click to toggle source

client_id={client_id}&refresh_token=G3Y6jU3a&grant_type=refresh_token& client_secret={client_secret}

# File lib/plangrade/oauth2_client.rb, line 82
def refresh!(token, opts={})
  opts[:authenticate] = :body
  refresh_token.get_token(token, opts)
end
webserver_authorization_url(opts={}) click to toggle source

Generates the Plangrade URL that the user will be redirected to in order to authorize your application

@see docs.plangrade.com/#request-authorization

@opts [Hash] additional parameters to be include in URL eg. scope, state, etc

>> client = Plangrade::OAuth2Client.new(‘ETSIGVSxmgZitijWZr0G6w’, ‘4bJZY38TCBB9q8IpkeualA2lZsPhOSclkkSKw3RXuE’) >> client.webserver_authorization_url({

  :redirect_uri => 'http://localhost:3000/auth/plangrade/callback',
})

>> plangrade.com/oauth/authorize/?client_id={client_id}&

redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fplangrade%2Fcallback&response_type=code
# File lib/plangrade/oauth2_client.rb, line 33
def webserver_authorization_url(opts={})
  opts[:scope] = normalize_scope(opts[:scope]) if opts[:scope]
  authorization_code.authorization_url(opts)
end