def oauth_login(oauth_server): if client := oauth.create_client(oauth_server): callback_url = flask.url_for('.handle_login', oauth_server=oauth_server, _external=True, _scheme='https') return client.authorize_redirect(callback_url)
def handle_login(oauth_server): if client := oauth.create_client(markupsafe.escape(oauth_server)): # Use authorization code to fetch OIDC info (https://openid.net/specs/openid-connect-core-1_0.html#IDToken) id_token = client.authorize_access_token() userinfo = client.parse_id_token(id_token) if user := db.users.find_one({ 'oauth_server': oauth_server, 'oauth_token': userinfo.sub }): # Account already exists login.login_user(User(user)) return redirect(flask.url_for('.page_courier'))
def login(name): client = oauth.create_client(name) if not client: abort(404) redirect_uri = url_for('auth.auth', name=name, _external=True) return client.authorize_redirect(redirect_uri)
def auth(name): client = oauth.create_client(name) if not client: abort(404) token = client.authorize_access_token() if 'id_token' in token: profile = client.parse_id_token(token) build_user_and_login(profile) else: resp = client.get('user', token=token) json = resp.json() profile = normalize_github_user(json) build_user_and_login(profile) return redirect('/')
def authorize(): google = oauth.create_client('google') token = google.authorize_access_token() resp = google.get('userinfo') user_info = resp.json() user = oauth.google.userinfo() session['profile'] = user_info profile = session['profile'] session.permanent = True # store in database user = models.User( id=profile['id'], first_name=profile['given_name'], last_name=profile['family_name']) db.session.merge(user) db.session.commit() redirecturl = f'http://localhost:3000/authorize?id=' + \ profile["id"] + '&name=' + profile["name"] return redirect(redirecturl)
def authorize(): google = oauth.create_client('google') # create the google oauth client token = (google.authorize_access_token() ) # Access token from google (needed to get user info) resp = google.get('userinfo') user_info = resp.json() user = oauth.google.userinfo() user_profile = User.query.filter_by(email=user_info['email']).first() if user_profile is None: user_profile = User(user_info['email'], user_info['given_name'], user_info['family_name']) db.session.add(user_profile) db.session.commit() session['profile'] = user_profile.get_map() session.permanent = ( True # make the session permanant so it keeps existing after broweser gets closed ) return redirect('/')
def authorize(): google = oauth.create_client('google') # create the google oauth client token = google.authorize_access_token( ) # Access token from google (needed to get user info) resp = google.get( 'userinfo') # userinfo contains stuff u specificed in the scrope user_info = resp.json() user = oauth.google.userinfo() # uses openid endpoint to fetch user info # Here you use the profile/user data that you got and query your database find/register the user # and set ur own data in the session not the profile from google user1 = dict(session).get('profile', None) #login_user(user1) #print("/*/*/*/*/*/*/**",user1.get("email")) session['logged_in'] = True logged = True print("lllllllll", logged) session['profile'] = user_info session.permanent = True # make the session permanant so it keeps existing after broweser gets closed if session['predict'] == True: return redirect('/predict') return redirect('/')
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)
def login(): google = oauth.create_client('google') # create the google oauth client redirect_uri = url_for('authorize', _external=True) return google.authorize_redirect(redirect_uri)