Skip to main content

adds NCTU-Oauth support to flask

Project description


台灣國立交通大學推出了 [NCTU Oauth](,現在,你可以透過本套件在 Flask 使用 NCTU Oauth。

依據[交通大學 OAuth 服務 - 開發者說明文件](進行相對應的開發,以下是一個使用本套件開發之範例。

#-*- 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'
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(

def home():
# check if login
if session.get('logged_in'):
# get user profile
return jsonify(nctu.get_profile())

return redirect('/login')

def login():
# redirect to nctu auth dialog
return nctu.authorize()

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__":

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for NCTU-Oauth, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size NCTU_Oauth-0.1.0-py2.7.egg (4.0 kB) File type Egg Python version 2.7 Upload date Hashes View
Filename, size NCTU-Oauth-0.1.0.tar.gz (2.3 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page