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 = ''
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()
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'])
def test_l2pauth():
return str(session.get('l2p_courses', {}))
def finish_oauth():
if 'l2p_oauthcode' not in session:
token = oauthget('token', code=session['l2p_oauthcode'], grant_type='device')
if token.get('status') != 'ok':
del session['l2p_oauthcode']
session['rwthintern'] = True
session['l2p_courses'] = []
for course in l2pget('viewAllCourseInfo', token['access_token'])['dataSet']:
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