From a5f163de7430be43556b87c97d862ce755532293 Mon Sep 17 00:00:00 2001 From: ansuha Date: Wed, 17 Apr 2024 23:11:29 -0400 Subject: [PATCH 1/8] Update settings.py to support google login Google auth settings update --- pollme/settings.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pollme/settings.py b/pollme/settings.py index e18c4f6345..664cfbe6ee 100644 --- a/pollme/settings.py +++ b/pollme/settings.py @@ -39,8 +39,15 @@ 'django.contrib.staticfiles', 'polls.apps.PollsConfig', 'accounts.apps.AccountsConfig', + 'allauth', + 'allauth.account', ] +AUTHENTICATION_BACKENDS = [ + 'allauth.account.auth_backends.AuthenticationBackend', + ] + + MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', @@ -49,6 +56,7 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'allauth.account.middleware.AccountMiddleware', ] ROOT_URLCONF = 'pollme.urls' @@ -123,3 +131,16 @@ STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ] + +SOCIALACCOUNT_PROVIDERS = { + 'google': { + 'SCOPE': [ + 'profile', + 'email', + ], + 'AUTH_PARAMS': { + 'access_type': 'online', + }, + 'OAUTH_PKCE_ENABLED': True, + } +} From 5aed64c1b713c5848c18a1205bda028d34bde5fd Mon Sep 17 00:00:00 2001 From: ansuha Date: Thu, 18 Apr 2024 12:40:43 -0400 Subject: [PATCH 2/8] Update requirements.txt added social-auth-app-django>=0.4.0 --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 73de26ecd9..d608e5d0f9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ asgiref==3.3.1 Django==3.1.14 pytz==2020.5 sqlparse==0.4.4 +social-auth-app-django>=0.4.0 From 585e7a21ae93403b6857cc87152582ded7a290f7 Mon Sep 17 00:00:00 2001 From: ansuha Date: Thu, 18 Apr 2024 12:42:44 -0400 Subject: [PATCH 3/8] Update settings.py to use social-auth-app-django --- pollme/settings.py | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/pollme/settings.py b/pollme/settings.py index 664cfbe6ee..1985f7cca6 100644 --- a/pollme/settings.py +++ b/pollme/settings.py @@ -31,6 +31,7 @@ # Application definition INSTALLED_APPS = [ + 'social_django', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -39,14 +40,12 @@ 'django.contrib.staticfiles', 'polls.apps.PollsConfig', 'accounts.apps.AccountsConfig', - 'allauth', - 'allauth.account', ] -AUTHENTICATION_BACKENDS = [ - 'allauth.account.auth_backends.AuthenticationBackend', - ] - +AUTHENTICATION_BACKENDS = ( + 'social_core.backends.google.GoogleOAuth2', + 'django.contrib.auth.backends.ModelBackend', +) MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', @@ -56,7 +55,6 @@ 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'allauth.account.middleware.AccountMiddleware', ] ROOT_URLCONF = 'pollme.urls' @@ -72,6 +70,8 @@ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'social_django.context_processors.backends', + 'social_django.context_processors.login_redirect', ], }, }, @@ -132,15 +132,7 @@ os.path.join(BASE_DIR, 'static') ] -SOCIALACCOUNT_PROVIDERS = { - 'google': { - 'SCOPE': [ - 'profile', - 'email', - ], - 'AUTH_PARAMS': { - 'access_type': 'online', - }, - 'OAUTH_PKCE_ENABLED': True, - } -} +SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id' +SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret' +SOCIAL_AUTH_URL_NAMESPACE = 'social' +SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/polls/list/user/' From a55e90e0345215f9d3d3e5dd7e54fd7ccc111784 Mon Sep 17 00:00:00 2001 From: ansuha Date: Sun, 28 Apr 2024 23:14:24 +0530 Subject: [PATCH 4/8] Update urls.py --- pollme/urls.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pollme/urls.py b/pollme/urls.py index ff6144e901..3d6f1a830f 100644 --- a/pollme/urls.py +++ b/pollme/urls.py @@ -22,4 +22,5 @@ path('admin/', admin.site.urls), path('accounts/', include('accounts.urls', namespace="accounts")), path('polls/', include('polls.urls', namespace="polls")), + path('', include('social_django.urls', namespace='social')), ] From 4e8ae88dd3d825193175d3088d69f4743121947e Mon Sep 17 00:00:00 2001 From: ansuha Date: Sun, 28 Apr 2024 23:15:26 +0530 Subject: [PATCH 5/8] Update login.html --- accounts/templates/accounts/login.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/accounts/templates/accounts/login.html b/accounts/templates/accounts/login.html index c571bcb094..0e6c8c18b2 100644 --- a/accounts/templates/accounts/login.html +++ b/accounts/templates/accounts/login.html @@ -3,6 +3,9 @@ {% block content %}
+ + Login with Google +

Login

{% if messages %}
@@ -38,4 +41,4 @@

Login

-{% endblock %} \ No newline at end of file +{% endblock %} From d2c533845fc109b906ddf62e951c7a2d4d5803bf Mon Sep 17 00:00:00 2001 From: ansuha Date: Sun, 28 Apr 2024 23:32:58 +0530 Subject: [PATCH 6/8] Update README.md --- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/README.md b/README.md index 21a55487a1..2b6958aa34 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,48 @@ Django poll app is a full featured polling app. You have to register in this app seeder.seed_all(30)

Here 30 is a number of entry. You can use it as your own

+

Obtaining OAuth Client ID for Google:

+ +To use Google's OAuth authentication in your application, you need to obtain a client ID and client secret. Follow these steps to get your OAuth client ID for Google: + +1. **Go to the Google Cloud Console:** + - Navigate to [Google Cloud Console](https://console.cloud.google.com/). + - Sign in with your Google account. + +2. **Create a new project:** + - Click on the project dropdown menu at the top of the page. + - Click on "New Project" and follow the prompts to create a new project. + +3. **Enable the Google Identity service:** + - In the Google Cloud Console, navigate to "APIs & Services" > "Dashboard." + - Click on "Enable APIs and Services." + - Search for "Google Identity" or "Google+ API" and enable it for your project. + +4. **Create OAuth consent screen:** + - In the Google Cloud Console, navigate to "APIs & Services" > "OAuth consent screen." + - Fill in the required fields (like application name, user support email, etc.). + - Add scopes (permissions) your application requires. + - Save the consent screen information. + +5. **Create OAuth credentials:** + - In the Google Cloud Console, navigate to "APIs & Services" > "Credentials." + - Click on "Create Credentials" > "OAuth client ID." + - Select "Web application" as the application type. + - Enter a name for your OAuth client. + - Add authorized redirect URIs : `http://127.0.0.1:8000/complete/google-oauth2/` + - Click "Create." + +6. **Copy the client ID and client secret:** + - Once the OAuth client is created, you'll see your client ID and client secret. + - Copy these values and update following variables in settings.py + + + SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id' + SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret' + + +For detailed instructions, refer to Google's documentation on [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2). +

To run the program in local server use the following command

python manage.py runserver From 3759b64e5c94c29402bc3c2575f138672ccb610f Mon Sep 17 00:00:00 2001 From: ansuha Date: Sun, 28 Apr 2024 23:33:31 +0530 Subject: [PATCH 7/8] Update README.md --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2b6958aa34..70c9c6ebcd 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,8 @@ To use Google's OAuth authentication in your application, you need to obtain a c - Once the OAuth client is created, you'll see your client ID and client secret. - Copy these values and update following variables in settings.py - - SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id' - SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret' - + SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id' + SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret' For detailed instructions, refer to Google's documentation on [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2). From 62fa032c23fa15c8bc6408c84c3b570b3a59656a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 May 2024 08:40:49 +0000 Subject: [PATCH 8/8] build(deps): bump sqlparse from 0.4.4 to 0.5.0 Bumps [sqlparse](https://github.com/andialbrecht/sqlparse) from 0.4.4 to 0.5.0. - [Changelog](https://github.com/andialbrecht/sqlparse/blob/master/CHANGELOG) - [Commits](https://github.com/andialbrecht/sqlparse/compare/0.4.4...0.5.0) --- updated-dependencies: - dependency-name: sqlparse dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d608e5d0f9..4cc0100058 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ asgiref==3.3.1 Django==3.1.14 pytz==2020.5 -sqlparse==0.4.4 +sqlparse==0.5.0 social-auth-app-django>=0.4.0