Skip to content

Commit 3d9b8d0

Browse files
Merge pull request #3 from ansuha/google-login-support
Google login support
2 parents 2519675 + 3759b64 commit 3d9b8d0

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,46 @@ Django poll app is a full featured polling app. You have to register in this app
2929
<code>seeder.seed_all(30)</code>
3030
<p>Here 30 is a number of entry. You can use it as your own</p>
3131

32+
<h2>Obtaining OAuth Client ID for Google:</h2>
33+
34+
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:
35+
36+
1. **Go to the Google Cloud Console:**
37+
- Navigate to [Google Cloud Console](https://console.cloud.google.com/).
38+
- Sign in with your Google account.
39+
40+
2. **Create a new project:**
41+
- Click on the project dropdown menu at the top of the page.
42+
- Click on "New Project" and follow the prompts to create a new project.
43+
44+
3. **Enable the Google Identity service:**
45+
- In the Google Cloud Console, navigate to "APIs & Services" > "Dashboard."
46+
- Click on "Enable APIs and Services."
47+
- Search for "Google Identity" or "Google+ API" and enable it for your project.
48+
49+
4. **Create OAuth consent screen:**
50+
- In the Google Cloud Console, navigate to "APIs & Services" > "OAuth consent screen."
51+
- Fill in the required fields (like application name, user support email, etc.).
52+
- Add scopes (permissions) your application requires.
53+
- Save the consent screen information.
54+
55+
5. **Create OAuth credentials:**
56+
- In the Google Cloud Console, navigate to "APIs & Services" > "Credentials."
57+
- Click on "Create Credentials" > "OAuth client ID."
58+
- Select "Web application" as the application type.
59+
- Enter a name for your OAuth client.
60+
- Add authorized redirect URIs : `http://127.0.0.1:8000/complete/google-oauth2/`
61+
- Click "Create."
62+
63+
6. **Copy the client ID and client secret:**
64+
- Once the OAuth client is created, you'll see your client ID and client secret.
65+
- Copy these values and update following variables in settings.py
66+
67+
<code>SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id'
68+
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret'</code>
69+
70+
For detailed instructions, refer to Google's documentation on [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2).
71+
3272
<h2> To run the program in local server use the following command </h2>
3373
<code>python manage.py runserver</code>
3474

accounts/templates/accounts/login.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
{% block content %}
44
<div class="vh-100 d-flex justify-content-center align-items-center p-5" id="login-content">
55
<div class="col-md-5 p-5 shadow-sm border rounded-5 border-primary bg-white">
6+
7+
<a href="{% url 'social:begin' 'google-oauth2' %}">Login with Google</a>
8+
69
<h2 class="text-center mb-4 text-primary">Login</h2>
710
{% if messages %}
811
<div class="messages">
@@ -38,4 +41,4 @@ <h2 class="text-center mb-4 text-primary">Login</h2>
3841
</div>
3942
</div>
4043
</div>
41-
{% endblock %}
44+
{% endblock %}

pollme/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@
2222
path('admin/', admin.site.urls),
2323
path('accounts/', include('accounts.urls', namespace="accounts")),
2424
path('polls/', include('polls.urls', namespace="polls")),
25+
path('', include('social_django.urls', namespace='social')),
2526
]

0 commit comments

Comments
 (0)