Make OAuth private methods actually private

This commit is contained in:
Rob Harrington
2017-07-07 15:21:30 +10:00
parent 42dd58426e
commit 5b675cbaba
2 changed files with 29 additions and 29 deletions

View File

@@ -1,9 +1,5 @@
module Stripe
class OAuth
class << self
attr_accessor :client, :options
end
@options = {
:site => 'https://connect.stripe.com',
:authorize_url => '/oauth/authorize',
@@ -14,38 +10,42 @@ module Stripe
@client = OAuth2::Client.new(
ENV['STRIPE_CLIENT_ID'],
ENV['STRIPE_INSTANCE_SECRET_KEY'],
options
@options
)
def self.authorize_url(enterprise_id, options = {})
options[:enterprise_id] = enterprise_id
jwt = jwt_encode(options)
# State param will be passed back after auth
client.auth_code.authorize_url(state: jwt, scope: 'read_write')
end
class << self
attr_accessor :client
def self.request_access_token(auth_code)
# Fetch and return the account details from Stripe
client.auth_code.get_token(auth_code).params
end
def authorize_url(enterprise_id, options = {})
options[:enterprise_id] = enterprise_id
jwt = jwt_encode(options)
# State param will be passed back after auth
client.auth_code.authorize_url(state: jwt, scope: 'read_write')
end
def self.deauthorize(stripe_user_id)
client.deauthorize(stripe_user_id).deauthorize_request
end
def request_access_token(auth_code)
# Fetch and return the account details from Stripe
client.auth_code.get_token(auth_code).params
end
private
def deauthorize(stripe_user_id)
client.deauthorize(stripe_user_id).deauthorize_request
end
def self.secret_token
Openfoodnetwork::Application.config.secret_token
end
private
def self.jwt_encode(payload)
JWT.encode(payload, secret_token, 'HS256')
end
def secret_token
Openfoodnetwork::Application.config.secret_token
end
def self.jwt_decode(token)
# Returns the original payload
JWT.decode(token, secret_token, true, algorithm: 'HS256')[0]
def jwt_encode(payload)
JWT.encode(payload, secret_token, 'HS256')
end
def jwt_decode(token)
# Returns the original payload
JWT.decode(token, secret_token, true, algorithm: 'HS256')[0]
end
end
end
end

View File

@@ -15,7 +15,7 @@ module Stripe
uri = URI.parse(url)
params = CGI.parse(uri.query)
expect(params.keys).to include 'client_id', 'response_type', 'state', 'scope'
expect(params["state"]).to eq [OAuth.jwt_encode(enterprise_id: enterprise_id)]
expect(params["state"]).to eq [OAuth.send(:jwt_encode, enterprise_id: enterprise_id)]
expect(uri.scheme).to eq 'https'
expect(uri.host).to eq 'connect.stripe.com'
expect(uri.path).to eq '/oauth/authorize'