access token through Authorization bearer

This commit is contained in:
kriss 2024-06-25 23:47:06 +02:00
parent 7478dee246
commit ea8100a764

12
app.py
View File

@ -3,7 +3,7 @@ import requests
from authlib.integrations.base_client import OAuthError
from authlib.integrations.flask_client import OAuth
from flask import Flask, request, redirect, session, render_template, url_for, make_response
from flask import Flask, request, redirect, Response, session, render_template, url_for, make_response
# TODO add client export json in project & git
@ -32,10 +32,14 @@ oauth.register(
@app.route("/api")
def api():
if 'accessToken' in request.cookies:
response = ''
if 'access_token' in request.cookies:
access_token = request.cookies['access_token']
print(access_token)
return make_response(redirect('http://localhost:5002/api?callbackUrl=http%3A%2F%2Flocalhost%3A5001'))
response = requests.get('http://localhost:5002/api?callbackUrl=http%3A%2F%2Flocalhost%3A5001', headers={'Authorization': f'Bearer {access_token}'})
else:
response = requests.get('http://localhost:5002/api?callbackUrl=http%3A%2F%2Flocalhost%3A5001')
return Response(response=response.text, status=response.status_code, headers=dict(response.headers))
@app.route("/auth")
def auth():