Exemplo n.º 1
0
"""
This module creates flask Blueprint for flask routes of this package
"""

from flask import Blueprint
from app import oauth
from config import Config

# assigning type Blueprint because mypy don't recognize type
bp: Blueprint = Blueprint(
    "auth",
    __name__,
)

google = oauth.register(
    name='google',
    client_id=Config.GOOGLE_CLIENT_ID,
    client_secret=Config.GOOGLE_CLIENT_SECRET,
    access_token_url='https://accounts.google.com/o/oauth2/token',
    access_token_params=None,
    authorize_url='https://accounts.google.com/o/oauth2/auth',
    authorize_params=None,
    api_base_url='https://www.googleapis.com/oauth2/v1/',
    userinfo_endpoint='https://openidconnect.googleapis.com/v1/userinfo',
    client_kwargs={'scope': 'openid email profile'},
)

from app.auth.routes import *
Exemplo n.º 2
0
from app import db, oauth
from app.models import User
from app.auth import blueprint
from flask import render_template, url_for, session, redirect
import os

oauth.register(
    name='github',
    authorize_url='https://github.com/login/oauth/authorize',
    access_token_url='https://github.com/login/oauth/access_token',
    client_id=os.getenv('GITHUB_CLIENT_ID'),
    client_secret=os.getenv('GITHUB_CLIENT_SECRET'),
    api_base_url='https://api.github.com'
)

oauth.register(
    name='google',
    client_id=os.getenv('GOOGLE_CLIENT_ID'),
    client_secret=os.getenv('GOOGLE_CLIENT_SECRECT'),
    server_metadata_url='https://accounts.google.com/.well-known/openid-configuration',
    client_kwargs={
        'scope': 'openid email profile'
    }
)

@blueprint.route('/login/<name>')
def login(name):

    client = oauth.create_client(name)
    if not client:
        abort(404)
'''
# dotenv setup
from dotenv import load_dotenv
load_dotenv()'''

auth2 = Blueprint('auth2', __name__, template_folder='templates')
# App config
# Session config
#auth2.secret_key = os.getenv("APP_SECRET_KEY")
google = oauth.register(
    name='google',
    client_id=
    "150632549688-ov4hd0n1ltfdtjrl4mrrt97v0mmonj7k.apps.googleusercontent.com",
    client_secret="zynpvwAoLqi0ie4sqYadeVh7",
    access_token_url='https://accounts.google.com/o/oauth2/token',
    access_token_params=None,
    authorize_url='https://accounts.google.com/o/oauth2/auth',
    authorize_params=None,
    api_base_url='https://www.googleapis.com/oauth2/v1/',
    userinfo_endpoint=
    'https://openidconnect.googleapis.com/v1/userinfo',  # This is only needed if using openId to fetch user info
    client_kwargs={'scope': 'openid email profile'},
)


@auth2.route('/login2')
def login():
    google = oauth.create_client('google')  # create the google oauth client
    #next_page = request.args['messages']
    redirect_uri = url_for('auth2.authorize', _external=True)
    return google.authorize_redirect(redirect_uri)
Exemplo n.º 4
0
from authlib.flask.client import OAuth
from app import oauth
import config
import os



oauth.register('google',
    client_id=os.environ.get('GOOGLE_CLIENT_ID'),
    client_secret=os.environ.get('GOOGLE_CLIENT_SECRET'),
    access_token_url='https://accounts.google.com/o/oauth2/token',
    access_token_params=None,
    refresh_token_url=None,
    authorize_url='https://accounts.google.com/o/oauth2/auth',
    api_base_url='https://www.googleapis.com/oauth2/v1/',
    client_kwargs={
        'scope': 'https://www.googleapis.com/auth/userinfo.email',
        'token_endpoint_auth_method': 'client_secret_basic',
        'token_placement': 'header',
        'prompt': 'consent'
    }
)
from werkzeug.urls import url_parse
from werkzeug.local import LocalProxy
from flask_login import login_user, logout_user, current_user, login_required
from flask_principal import identity_changed, Identity, AnonymousIdentity
from app import db, oauth, Config
from app.auth import bp
from app.auth.forms import LoginForm, RegistrationForm
from app.models import User
from app.auth.auth0_management_api import get_user

auth0 = oauth.register(
    'auth0',
    client_id=Config.AUTH0_CLIENT_ID,
    client_secret=Config.AUTH0_CLIENT_SECRET,
    api_base_url=Config.AUTH0_BASE_URL,
    access_token_url=Config.AUTH0_BASE_URL + '/oauth/token',
    authorize_url=Config.AUTH0_BASE_URL + '/authorize',
    client_kwargs={
        'scope': 'openid profile email',
    },
)


@bp.route('/login')
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    next_page = request.args.get('next')
    session['next'] = next_page