Created
February 26, 2020 19:46
-
-
Save spinolacastro/f42db09ac93c17b9ca60e86014878117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, url_for, redirect, request, session | |
from config import Config | |
from authlib.integrations.flask_client import OAuth | |
CLIENT_ID = 'ASLAKSJD' | |
CLIENT_SECRET = 'ASLDKJALSKDJA' | |
API_BASE_URL = 'https://api.contaazul.com' | |
REDIRECT_URI = 'https://091e727c.ngrok.io/callback' | |
AUTHORIZE_URL = API_BASE_URL + '/auth/authorize' | |
ACCESS_TOKEN_URL = API_BASE_URL + '/oauth2/token' | |
app = Flask(__name__) | |
app.config.from_object(Config) | |
oauth = OAuth(app) | |
oauth.register('contaazul', | |
client_id=CLIENT_ID, | |
client_secret=CLIENT_SECRET, | |
redirect_uri=REDIRECT_URI, | |
authorize_url=AUTHORIZE_URL, | |
api_base_url=API_BASE_URL, | |
access_token_url=ACCESS_TOKEN_URL, | |
client_kwargs={'scope': 'sales'}, | |
) | |
@app.route('/') | |
def hello_world(): | |
return 'Hello, World!' | |
@app.route('/callback') | |
def authorize(): | |
token = oauth.contaazul.authorize_access_token() | |
#user = contaazul.parse_id_token(token) | |
#session['token'] = token | |
return redirect('/produtos') | |
@app.route('/produtos') | |
def produtos(): | |
#token = session.get('token') | |
resp = oauth.contaazul.get('/v1/products/') | |
produtos = resp.json() | |
return produtos | |
@app.route('/login') | |
def login(): | |
#redirect_uri = url_for('authorize', _external=True) | |
return oauth.contaazul.authorize_redirect(REDIRECT_URI) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment