adds NCTU-Oauth support to flask
Project description
#NCTU-Oauth
台灣國立交通大學推出了 [NCTU Oauth](https://id.nctu.edu.tw/),現在,你可以透過本套件在 Flask 使用 NCTU Oauth。
依據[交通大學 OAuth 服務 - 開發者說明文件](https://id.nctu.edu.tw/docs/)進行相對應的開發,以下是一個使用本套件開發之範例。
```Python
#-*- encoding: UTF-8 -*-
from flask import Flask, session, request, redirect, jsonify
# Our oauth
from nctu_oauth import Oauth
NCTU_APP_REDIRECT_URI = 'In this example is http://your.domain.name/auth'
NCTU_APP_CLIENT_ID = 'your client id'
NCTU_APP_CLIENT_SECRET = 'your client secret'
app = Flask(__name__)
app.secret_key = 'your super coll secrey key'
# make a oauth init
nctu = Oauth(
redirect_uri=NCTU_APP_REDIRECT_URI,
client_id=NCTU_APP_CLIENT_ID,
client_secret=NCTU_APP_CLIENT_SECRET
)
@app.route("/")
def home():
# check if login
if session.get('logged_in'):
# get user profile
return jsonify(nctu.get_profile())
return redirect('/login')
@app.route('/login')
def login():
# redirect to nctu auth dialog
return nctu.authorize()
@app.route('/auth')
def auth():
# user code for getting token
code = request.args.get('code')
if code:
#get user token
if nctu.get_token(code):
return redirect('/')
return redirect('/login')
if __name__ == "__main__":
app.run()
```
台灣國立交通大學推出了 [NCTU Oauth](https://id.nctu.edu.tw/),現在,你可以透過本套件在 Flask 使用 NCTU Oauth。
依據[交通大學 OAuth 服務 - 開發者說明文件](https://id.nctu.edu.tw/docs/)進行相對應的開發,以下是一個使用本套件開發之範例。
```Python
#-*- encoding: UTF-8 -*-
from flask import Flask, session, request, redirect, jsonify
# Our oauth
from nctu_oauth import Oauth
NCTU_APP_REDIRECT_URI = 'In this example is http://your.domain.name/auth'
NCTU_APP_CLIENT_ID = 'your client id'
NCTU_APP_CLIENT_SECRET = 'your client secret'
app = Flask(__name__)
app.secret_key = 'your super coll secrey key'
# make a oauth init
nctu = Oauth(
redirect_uri=NCTU_APP_REDIRECT_URI,
client_id=NCTU_APP_CLIENT_ID,
client_secret=NCTU_APP_CLIENT_SECRET
)
@app.route("/")
def home():
# check if login
if session.get('logged_in'):
# get user profile
return jsonify(nctu.get_profile())
return redirect('/login')
@app.route('/login')
def login():
# redirect to nctu auth dialog
return nctu.authorize()
@app.route('/auth')
def auth():
# user code for getting token
code = request.args.get('code')
if code:
#get user token
if nctu.get_token(code):
return redirect('/')
return redirect('/login')
if __name__ == "__main__":
app.run()
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
NCTU-Oauth-0.1.0.tar.gz
(2.3 kB
view details)
Built Distribution
NCTU_Oauth-0.1.0-py2.7.egg
(4.0 kB
view details)
File details
Details for the file NCTU-Oauth-0.1.0.tar.gz
.
File metadata
- Download URL: NCTU-Oauth-0.1.0.tar.gz
- Upload date:
- Size: 2.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c86f749f003035c9ba6665b88ca679969aee956a4b2ebce52427dd3bddf36697 |
|
MD5 | 45b60a732e435a62dad6497ab635d830 |
|
BLAKE2b-256 | 2bb8c3f9ffe1692a1e22786b7bcd3901c4c2b2ccfee9c66fd2a92438d8758aa6 |
File details
Details for the file NCTU_Oauth-0.1.0-py2.7.egg
.
File metadata
- Download URL: NCTU_Oauth-0.1.0-py2.7.egg
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77673c70ec39f89564004242bd174594a8b83a33f8777e1343528bea19d8eae0 |
|
MD5 | aaa576b408608fe56e596d305363263a |
|
BLAKE2b-256 | 5e07c6508378015a0c79d81c8878b7163e7ab97f21ecbb911a752c60eb927605 |