-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfake_auth_server.py
42 lines (26 loc) · 1.09 KB
/
fake_auth_server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from urllib.parse import urlencode
from flask import Flask, request, Response, redirect, jsonify
app = Flask(__name__)
@app.get("/auth")
def auth():
state = request.args['state']
client_id = request.args['client_id']
redirect_uri = request.args['redirect_uri']
if client_id != 'some_client_id':
return Response("Unauthorized", status=401)
query_string = urlencode({'state': state, 'code': 'some_code'})
return redirect(f'{redirect_uri}?{query_string}')
@app.post("/token")
def access_token():
if (request.form['client_id'] != 'some_client_id'
or request.form['client_secret'] != 'some_client_secret'
or request.form['code'] != 'some_code'):
return Response("Unauthorized", status=401)
return jsonify({"access_token": "some_access_token"})
@app.get("/userinfo")
def userinfo():
auth_header = request.headers["Authorization"]
if auth_header != "Bearer some_access_token":
return Response("Unauthorized", status=401)
return jsonify({"email": "[email protected]"})
app.run(debug=True, host="0.0.0.0", port=8999)