Commit 86d71023 authored by Julian Rother's avatar Julian Rother
Browse files

Implemented basic L2P API interface

parent a6fd310f
from server import *
import requests
import json
from time import sleep
L2P_BASE = 'https://www3.elearning.rwth-aachen.de/_vti_bin/l2pservices/api.svc/v1/'
OAUTH_BASE = 'https://oauth.campus.rwth-aachen.de/oauth2waitress/oauth2.svc/'
def l2pget(endpoint, token, **args):
args['accessToken'] = token
r = requests.request('GET', L2P_BASE+endpoint, params=args)
return r.json()
def oauthget(endpoint, **args):
args['client_id'] = config['L2P_APIKEY']
r = requests.request('POST', OAUTH_BASE+endpoint, data=args)
return r.json()
@app.route('/l2pauth')
def start_l2pauth():
code = oauthget('code', scope='l2p2013.rwth')
session['l2p_oauthcode'] = code['device_code']
return redirect(code['verification_url']+'?q=verify&d='+code['user_code'])
@app.route('/l2p')
def test_l2pauth():
return str(session.get('l2p_courses', {}))
@app.before_request
def finish_oauth():
if 'l2p_oauthcode' not in session:
return
token = oauthget('token', code=session['l2p_oauthcode'], grant_type='device')
if token.get('status') != 'ok':
return
del session['l2p_oauthcode']
session['rwthintern'] = True
session['l2p_courses'] = []
for course in l2pget('viewAllCourseInfo', token['access_token'])['dataSet']:
session['l2p_courses'].append(course['uniqueid'])
oauthget('token', refresh_token=token['refresh_token'], grant_type='invalidate')
flash('Folgende Kurse wurden freigegeben: '+', '.join(session['l2p_courses']))
......@@ -468,3 +468,5 @@ import timetable
import sorter
if 'ICAL_URL' in config:
import meetings
if 'L2P_APIKEY' in config:
import l2pauth
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment