Integrating Google Sign-In into your Flask web application allows users to log in and access your services using their Google accounts. In this guide, we'll explore how to create a Flask app with Google Sign-In, enabling users to authenticate themselves and access your application securely. By following this guide, you'll be able to implement Google Sign-In and utilize user authentication for your Flask app.

Step 1: Setting Up Your Flask Application

Start by setting up your Flask application and creating a directory structure. Here's a sample structure:


Step 2: Installing Flask and Required Libraries

Install Flask and the necessary libraries to support Google Sign-In. You can use pip to install the required packages:

pip install Flask
pip install Flask-OAuthlib

Step 3: Creating a Google API Project

Create a Google API project in the Google Developers Console. Configure OAuth 2.0 credentials for your project and obtain a client ID and client secret.

Step 4: Configuring Google Sign-In in Your Flask App

Configure Google Sign-In in your Flask application. Here's an example of Python code:

from flask import Flask, render_template, redirect, url_for, session
from flask_oauthlib.client import OAuth
app = Flask(__name__)
app.secret_key = 'your_secret_key'
oauth = OAuth(app)
google = oauth.remote_app(
'scope': 'email',
def home():
return 'Welcome to the home page. <a href="/login">Login with Google</a>'
def login():
return google.authorize(callback=url_for('authorized', _external=True))
def logout():
session.pop('google_token', None)
return 'Logged out successfully. <a href="/">Home</a>'
def authorized():
response = google.authorized_response()
if response is None or response.get('access_token') is None:
return 'Access denied: reason={} error={}'.format(
session['google_token'] = (response['access_token'], '')
user_info = google.get('userinfo')
return render_template('dashboard.html',
def get_google_oauth_token():
return session.get('google_token')
if __name__ == '__main__':

Step 5: Creating Login and Dashboard Templates

Create HTML templates for the login and dashboard pages. Here's an example of a login button:

<!-- templates/login.html -->
<!DOCTYPE html>
<a href="/login">Login with Google</a>

And here's an example of a dashboard page:

<!-- templates/dashboard.html -->
<!DOCTYPE html>
<h1>Welcome, {{ }}</h1>
<p>Email: {{ }}</p>
<a href="/logout">Logout</a>


Implementing Google Sign-In in your Flask application provides a convenient way for users to log in using their Google accounts. By following this guide, you've learned how to set up your Flask app, configure Google Sign-In, and create login and dashboard pages. You can now add Google Sign-In functionality to your Flask application and provide users with a seamless authentication experience.