Fixed mTLS certificate verification
This commit is contained in:
parent
22449e7ce1
commit
3a4d65ff5d
45
bbpay.py
45
bbpay.py
@ -20,25 +20,13 @@ app = Flask(__name__)
|
|||||||
CORS(app)
|
CORS(app)
|
||||||
api = Api(app)
|
api = Api(app)
|
||||||
|
|
||||||
class BBPay(Resource):
|
class BBPay(Resource):
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.setup_oauth()
|
|
||||||
|
|
||||||
def setup_oauth(self):
|
def setup_oauth(self):
|
||||||
client = BackendApplicationClient(client_id=getenv("CLIENT_ID"))
|
client = BackendApplicationClient(client_id=getenv("CLIENT_ID"))
|
||||||
self.oauth = OAuth2Session(client=client)
|
self.oauth = OAuth2Session(client=client)
|
||||||
|
|
||||||
scope = ['checkout.solicitacoes-requisicao',
|
self.cert = 'key.pem'
|
||||||
'checkout.participantes-requisicao',
|
self.verify_ssl = 'bb.pem'
|
||||||
'checkout.solicitacoes-info',
|
|
||||||
'checkout.participantes-info']
|
|
||||||
|
|
||||||
self.oauth.fetch_token(
|
|
||||||
token_url='https://oauth.hm.bb.com.br/oauth/token',
|
|
||||||
client_id=getenv("CLIENT_ID"),
|
|
||||||
client_secret=getenv("CLIENT_SECRET"), scope=scope,
|
|
||||||
cert='cert.pem')
|
|
||||||
|
|
||||||
# Url de homologação com autenticação mTLS.
|
# Url de homologação com autenticação mTLS.
|
||||||
self.baseUrl = "https://api-bbpay.hm.bb.com.br/checkout/v2"
|
self.baseUrl = "https://api-bbpay.hm.bb.com.br/checkout/v2"
|
||||||
@ -49,13 +37,25 @@ class BBPay(Resource):
|
|||||||
# Url de produção com autenticação mTLS.
|
# Url de produção com autenticação mTLS.
|
||||||
#self.baseUrl = "https://api-bbpay.bb.com.br/checkout/v2"
|
#self.baseUrl = "https://api-bbpay.bb.com.br/checkout/v2"
|
||||||
|
|
||||||
self.verify_ssl = False
|
|
||||||
|
|
||||||
self.params = {
|
self.params = {
|
||||||
'numeroConvenio': 701,
|
'numeroConvenio': 701,
|
||||||
'gw-dev-app-key': getenv("DEV_APP_KEY")
|
'gw-dev-app-key': getenv("DEV_APP_KEY")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.scope = ['checkout.solicitacoes-requisicao',
|
||||||
|
'checkout.participantes-requisicao',
|
||||||
|
'checkout.solicitacoes-info',
|
||||||
|
'checkout.participantes-info']
|
||||||
|
|
||||||
|
self.oauth.fetch_token(
|
||||||
|
token_url='https://oauth.hm.bb.com.br/oauth/token',
|
||||||
|
client_id=getenv("CLIENT_ID"),
|
||||||
|
client_secret=getenv("CLIENT_SECRET"), scope=self.scope)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setup_oauth()
|
||||||
|
|
||||||
class Register(BBPay):
|
class Register(BBPay):
|
||||||
def post(self):
|
def post(self):
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
@ -74,7 +74,7 @@ class Register(BBPay):
|
|||||||
params=self.params,
|
params=self.params,
|
||||||
json=body,
|
json=body,
|
||||||
verify=self.verify_ssl,
|
verify=self.verify_ssl,
|
||||||
cert='cert.pem')
|
cert=self.cert)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Request(BBPay):
|
class Request(BBPay):
|
||||||
@ -104,7 +104,8 @@ class Request(BBPay):
|
|||||||
self.baseUrl+"/solicitacoes",
|
self.baseUrl+"/solicitacoes",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
json=body,
|
json=body,
|
||||||
verify=self.verify_ssl)
|
verify=self.verify_ssl,
|
||||||
|
cert=self.cert)
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
class Release(BBPay):
|
class Release(BBPay):
|
||||||
@ -112,7 +113,8 @@ class Release(BBPay):
|
|||||||
response = self.oauth.get(
|
response = self.oauth.get(
|
||||||
self.baseUrl+f"/solicitacoes/{numeroSolicitacao}",
|
self.baseUrl+f"/solicitacoes/{numeroSolicitacao}",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
verify=self.verify_ssl)
|
verify=self.verify_ssl,
|
||||||
|
cert=self.cert)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return 'Upstream error', response.status_code
|
return 'Upstream error', response.status_code
|
||||||
data = response.json()
|
data = response.json()
|
||||||
@ -125,7 +127,8 @@ class Release(BBPay):
|
|||||||
response = self.oauth.get(
|
response = self.oauth.get(
|
||||||
self.baseUrl+f"/participantes/{numeroParticipante}",
|
self.baseUrl+f"/participantes/{numeroParticipante}",
|
||||||
params=self.params,
|
params=self.params,
|
||||||
verify=self.verify_ssl)
|
verify=self.verify_ssl,
|
||||||
|
cert=self.cert)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return 'Upstream error', response.status_code
|
return 'Upstream error', response.status_code
|
||||||
chainID = response.json()['nomeParticipante']
|
chainID = response.json()['nomeParticipante']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user