Skip to content

Commit 867c661

Browse files
authored
Merge pull request #34 from ansuha/master
Added support for Linkedin OAuth based login
2 parents 7e56051 + f7cd0f7 commit 867c661

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

README.md

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ 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:
32+
<h2> Configuring OAuth login </h2>
33+
<details>
34+
<summary>Obtaining OAuth Client ID for Google</summary>
3535

3636
1. **Go to the Google Cloud Console:**
3737
- Navigate to [Google Cloud Console](https://console.cloud.google.com/).
@@ -62,12 +62,34 @@ To use Google's OAuth authentication in your application, you need to obtain a c
6262

6363
6. **Copy the client ID and client secret:**
6464
- 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
65+
- Copy these values and update the following variables in settings.py
6666

67-
<code>SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id'
68-
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret'</code>
67+
```
68+
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id'
69+
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'your-client-secret'
70+
```
6971
7072
For detailed instructions, refer to Google's documentation on [OAuth 2.0](https://developers.google.com/identity/protocols/oauth2).
73+
</details>
74+
75+
76+
<details>
77+
<summary>Obtaining OAuth Client ID for LinkedIn</summary>
78+
79+
### Step 1: Create a LinkedIn App
80+
1. Go to the [LinkedIn Developer Portal](https://www.linkedin.com/developers/) and sign in.
81+
2. Click on "Create App" and fill in the required details, such as the app name, description, and logo.
82+
3. In the "Authorized Redirect URLs" section, add the callback URL for your Django app. This URL will be like `http://127.0.0.1:8000/complete/linkedin/`.
83+
4. Save the changes and note down the Client ID and Client Secret provided by LinkedIn.
84+
85+
### Step 2: Configure Django Settings
86+
87+
1. Update the following settings to your settings file, replacing `'your-linkedin-client-id'` and `'your-linkedin-client-secret'` with your actual LinkedIn app credentials:
88+
```python
89+
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'your-client-id'
90+
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'your-client-secret'
91+
```
92+
</details>
7193
7294
<h2> To run the program in local server use the following command </h2>
7395
<code>python manage.py runserver</code>

accounts/templates/accounts/login.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
{% extends 'base.html' %}
2+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
23

34
{% block content %}
45
<div class="vh-100 d-flex justify-content-center align-items-center p-5" id="login-content">
56
<div class="col-md-5 p-5 shadow-sm border rounded-5 border-primary bg-white">
67

7-
<a href="{% url 'social:begin' 'google-oauth2' %}">Login with Google</a>
8-
8+
<div class="social-login">
9+
<a href="{% url 'social:begin' 'google-oauth2' %}" class="social-login-link" data-tooltip="Login with Google">
10+
Login with <i class="fab fa-google social-login-icon"></i>oogle
11+
</a>
12+
<a href="{% url 'social:begin' 'linkedin-oauth2' %}" class="social-login-link" data-tooltip="Login with LinkedIn">
13+
Login with Linked<i class="fab fa-linkedin-in social-login-icon"></i>
14+
</a>
15+
</div>
916
<h2 class="text-center mb-4 text-primary">Login</h2>
1017
{% if messages %}
1118
<div class="messages">

pollme/settings.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
AUTHENTICATION_BACKENDS = (
4646
'social_core.backends.google.GoogleOAuth2',
47+
'social_core.backends.linkedin.LinkedinOAuth2',
4748
'django.contrib.auth.backends.ModelBackend',
4849
)
4950

@@ -134,5 +135,8 @@
134135

135136
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'your-client-id'
136137
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET ='your-client-secret'
138+
SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'your-client-id'
139+
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'your-client-secret'
140+
137141
SOCIAL_AUTH_URL_NAMESPACE = 'social'
138142
SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/polls/list/user/'

0 commit comments

Comments
 (0)