hw_oauth/website/home/routes.py

26 lines
619 B
Python

from . import home
from flask import Blueprint, render_template, jsonify
from flask_login import current_user
from authlib.integrations.flask_oauth2 import current_token
from ..auth.oauth2 import require_oauth
@home.route('/')
def index():
user = None
if current_user.is_authenticated:
clients = current_user.clients
user = current_user.name
else:
clients = []
return render_template('home.html', user=user, clients=clients)
@home.route('/api/me')
@require_oauth('profile')
def api_me():
user = current_token.user
return jsonify(id=user.id, username=user.username)