-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py.template
54 lines (40 loc) · 1.55 KB
/
main.py.template
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
43
44
45
46
47
48
49
50
51
52
53
54
from oauth.oauth_flask import *
from flask import Flask, render_template
VERSION = '1.0.0'
app = Flask(__name__)
d = {}
d['oauth_client_id'] = 'gitlabclient_idXXX'
d['oauth_client_secret'] = 'gitlabclient_secretXXX'
d['client_uri'] = 'http://example.com'
oauth = OAuth(**d)
oauth.load_defaults(provider="gitlab", provider_uri="https://git.example.com")
oauth.default_routes(sign_in = "/sign_in", sign_out = "/logout", get_token = "/auth", app = app)
d2 = {}
d2['oauth_client_id'] = 'githubclient_idXXX'
d2['oauth_client_secret'] = 'githubclient_idXXX'
d2['client_uri'] = 'http://example.com'
oauth2 = OAuth(**d2)
oauth2.load_defaults(provider="github")
oauth2.default_routes(sign_in = "/sign_in2", app=app)
# Attention!!!! default rules for multiple OAuth Instances cannot have same name
@app.route("/")
def init():
if oauth.is_oauth_session() == False and oauth2.is_oauth_session() == False:
return render_template('signin.html')
return "Logged in as "+request.cookies.get('login')
# cookies: login, fullname, email, logout_uri
# logout_uri is used to determine which sign_out-Route to call
@app.route("/gitlab")
@oauth.protect()
def gitlab():
return "Only access from GitLab Sign-On"
@app.route("/github", role="admin") # Only access for admins, default role="all"
@oauth2.protect()
def github():
return "Only access from GitHub Sign-On"
@app.route("/access_for_all")
@multi_oauth([oauth, oauth2], role="admin") # Only access for admins
def all()÷
return "Access for all OAuth Provider Sign-Ons"
if __name__ == '__main__':
app.run(host='127.0.0.1', port=5000)