class Sorcery::Providers::Paypal

This class adds support for OAuth with paypal.com.

config.paypal.key = <key>
config.paypal.secret = <secret>
...

Attributes

auth_url[RW]
scope[RW]
token_url[RW]
user_info_url[RW]

Public Class Methods

new() click to toggle source
Calls superclass method Sorcery::Providers::Base::new
# File lib/sorcery/providers/paypal.rb, line 14
def initialize
  super

  @scope           = 'openid email'
  @site            = 'https://api.paypal.com'
  @auth_url        = 'https://www.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize'
  @user_info_url   = 'https://api.paypal.com/v1/identity/openidconnect/userinfo?schema=openid'
  @token_url       = 'https://api.paypal.com/v1/identity/openidconnect/tokenservice'
  @state           = SecureRandom.hex(16)
end

Public Instance Methods

get_access_token(args, options = {}) click to toggle source
# File lib/sorcery/providers/paypal.rb, line 35
def get_access_token(args, options = {})
  client = build_client(options)
  client.auth_code.get_token(
    args[:code],
    {
      redirect_uri: @callback_url,
      parse: options.delete(:parse)
    },
    options
  )
end
get_user_hash(access_token) click to toggle source
# File lib/sorcery/providers/paypal.rb, line 25
def get_user_hash(access_token)
  response = access_token.get(user_info_url)
  body = JSON.parse(response.body)
  auth_hash(access_token).tap do |h|
    h[:user_info] = body
    h[:uid] = body['user_id']
    h[:email] = body['email']
  end
end
login_url(_params, _session) click to toggle source
# File lib/sorcery/providers/paypal.rb, line 47
def login_url(_params, _session)
  authorize_url(authorize_url: auth_url)
end
process_callback(params, _session) click to toggle source
# File lib/sorcery/providers/paypal.rb, line 51
def process_callback(params, _session)
  args = {}.tap do |a|
    a[:code] = params[:code] if params[:code]
  end

  get_access_token(args, token_url: token_url, token_method: :post)
end