Skip to content

Instantly share code, notes, and snippets.

@twyle
Last active June 2, 2022 09:56
Show Gist options
  • Save twyle/81021e89433451d2e43faa2607131de0 to your computer and use it in GitHub Desktop.
Save twyle/81021e89433451d2e43faa2607131de0 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""This module contains initialization code for the api package."""
from flask import Flask, redirect, url_for
from api.helpers import set_flask_environment
from .blueprints.default.views import default
from .blueprints.auth.views import auth
from flask_dance.contrib.github import github
app = Flask(__name__)
set_flask_environment(app=app)
app.register_blueprint(default)
app.register_blueprint(auth, url_prefix='/login')
@app.route('/github')
def login():
"""Log in a registered or authenticated user."""
if not github.authorized:
return redirect(url_for('github.login'))
res = github.get('/user')
return f"You are logged in as {res.json()['login']} on GitHub."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment