mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Make OAuth private methods actually private
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user