Skip to content

Commit

Permalink
Add Google oAuth integration (#1045)
Browse files Browse the repository at this point in the history
  • Loading branch information
halfmoonui authored Feb 20, 2024
1 parent 6ccf666 commit af64d6a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 22 deletions.
4 changes: 4 additions & 0 deletions backend/.envs/.env.local
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ APPLE_WALLET_TEAM_ID=""
# STRIPE
# ------------------------------------------------------------------------------
STRIPE_API_KEY="sk_test_51KvpFEJ8LTYPBcCzE6lXIAoQ3zG8MCGlZMeCdfQTVn5ewN2tymAHYPsjM7NP90VpAG7NEumlfhCJoyRsPrEsZiRx00H2oDqiNR"

# OAUTH
# ------------------------------------------------------------------------------
GOOGLE_OAUTH_CLIENT_SECRET=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
6 changes: 5 additions & 1 deletion backend/.envs/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,8 @@ APPLE_WALLET_TEAM_ID=""

# STRIPE
# ------------------------------------------------------------------------------
STRIPE_API_KEY=""
STRIPE_API_KEY=""

# OAUTH
# ------------------------------------------------------------------------------
GOOGLE_OAUTH_CLIENT_SECRET=""
4 changes: 4 additions & 0 deletions backend/.envs/.env.test
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,7 @@ APPLE_WALLET_TEAM_ID="Team Identifier"
# STRIPE
# ------------------------------------------------------------------------------
STRIPE_API_KEY="sk_test_51KvpFEJ8LTYPBcCzE6lXIAoQ3zG8MCGlZMeCdfQTVn5ewN2tymAHYPsjM7NP90VpAG7NEumlfhCJoyRsPrEsZiRx00H2oDqiNR"

# OAUTH
# ------------------------------------------------------------------------------
GOOGLE_OAUTH_CLIENT_SECRET=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
8 changes: 4 additions & 4 deletions backend/apps/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
path("", include("apps.marketing.urls")),
# Event Checkout
path("", include("apps.checkout.urls")),
# User Auth / Organizer Dashboard
# Note: First path ("dashboard/accounts/") is kept for backwards compatibility
path("dashboard/accounts/", include("allauth.urls")),
path("", include("allauth.urls")),
# User Auth
path("accounts/", include("allauth.urls")),
path("accounts/", include("allauth.socialaccount.urls")),
# Organizer Dashboard
path("dashboard/", include("apps.dashboard_organizer.urls")),
# Staff Dashboard
path(settings.STAFF_URL, include("apps.dashboard_staff.urls")),
Expand Down
29 changes: 22 additions & 7 deletions backend/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.google",
"crispy_forms",
"crispy_bootstrap5",
"django_quill",
Expand Down Expand Up @@ -120,6 +121,23 @@
LOGIN_REDIRECT_URL = "dashboard_organizer:dashboard_redirect"
# https://docs.djangoproject.com/en/dev/ref/settings/#login-url
LOGIN_URL = "account_login"
# https://docs.allauth.org/en/latest/socialaccount/index.html
SOCIALACCOUNT_PROVIDERS = {
"google": {
"APP": {
"client_id": "949645827365-rok4geldv705aoi0qaccn1qigg8g8gtq.apps.googleusercontent.com",
"secret": env("GOOGLE_OAUTH_CLIENT_SECRET"),
"key": ""
},
"SCOPE": [
"profile",
"email",
],
"AUTH_PARAMS": {
"access_type": "online",
}
}
}

# PASSWORDS
# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -274,12 +292,6 @@
# https://django-allauth.readthedocs.io/en/latest/configuration.html
ACCOUNT_EMAIL_VERIFICATION = "mandatory"

# https://django-allauth.readthedocs.io/en/latest/configuration.html
SOCIALACCOUNT_ADAPTER = "apps.root.adapters.SocialAccountAdapter"

# https://django-allauth.readthedocs.io/en/latest/forms.html
SOCIALACCOUNT_FORMS = {"signup": "apps.root.forms.UserSocialSignupForm"}

# https://django-allauth.readthedocs.io/en/latest/views.html#logout-account-logout
ACCOUNT_LOGOUT_ON_GET = True

Expand All @@ -290,7 +302,10 @@
# Note: Allows for email-only auth
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_AUTHENTICATION_METHOD = "email"

# https://docs.allauth.org/en/latest/socialaccount/configuration.html
SOCIALACCOUNT_LOGIN_ON_GET = True

# Your stuff...
# INTERNAL
Expand Down
1 change: 1 addition & 0 deletions backend/static/images/g-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 10 additions & 5 deletions backend/templates/account/login.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% extends "account/base.html" %}
{% load account static i18n %}
{% load account socialaccount static i18n %}

{% block head_title %}{% trans "Sign In" %} - SocialPass{% endblock %}

Expand All @@ -11,10 +11,15 @@
{% trans "Please sign in to your account to continue." %}
</div>
{% endif %}
<h1 class="h3 mb-0">{% trans "Sign In" %}</h1>
<p class="text-body-secondary">
{% trans "Please enter your credentials to sign in to your account." %}
</p>
<h1 class="h3 mb-4">{% trans "Sign In" %}</h1>
<a class="btn btn-secondary d-flex align-items-center justify-content-center w-100 py-2 mb-3" href="{% provider_login_url 'google' %}">
<img src="{% static 'images/g-logo.svg' %}" alt="Google" height="28px" class="d-block w-auto me-2">
{% trans "Sign in with Google" %}
</a>
<div class="position-relative my-4 opacity-50">
<hr />
<div class="position-absolute top-50 start-50 translate-middle px-3 text-body-secondary" style="background-color: var(--bs-content-bg);">{% trans "OR" %}</div>
</div>
<form class="login" method="POST" action="{% url 'account_login' %}">
{% csrf_token %}
{% if form.non_field_errors %}
Expand Down
15 changes: 10 additions & 5 deletions backend/templates/account/signup.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{% extends "account/base.html" %}
{% load account static i18n %}
{% load account socialaccount static i18n %}

{% block head_title %}{% trans "Sign Up" %} - SocialPass{% endblock %}

{% block inner %}
<div class="card border-0 rounded-4 shadow-sm">
<div class="card-body p-lg-4">
<h1 class="h3 mb-0">{% trans "Sign Up" %}</h1>
<p class="text-body-secondary">
{% trans "Please fill out the following form to sign up and create your account." %}
</p>
<h1 class="h3 mb-4">{% trans "Sign Up" %}</h1>
<a class="btn btn-secondary d-flex align-items-center justify-content-center w-100 py-2 mb-3" href="{% provider_login_url 'google' %}">
<img src="{% static 'images/g-logo.svg' %}" alt="Google" height="28px" class="d-block w-auto me-2">
{% trans "Sign up with Google" %}
</a>
<div class="position-relative my-4 opacity-50">
<hr />
<div class="position-absolute top-50 start-50 translate-middle px-3 text-body-secondary" style="background-color: var(--bs-content-bg);">{% trans "OR" %}</div>
</div>
<form class="signup" method="POST" action="{% url 'account_signup' %}">
{% csrf_token %}
{% if form.non_field_errors %}
Expand Down

0 comments on commit af64d6a

Please sign in to comment.