Skip to content

Commit

Permalink
feat!: New version
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
* Remove Django 4.1 support
* Add Django 5.0 support
* Fix `SSO_USE_ALTERNATE_W003` bug
* Fix several CSS issues with custom logo images
* Update docs
  • Loading branch information
chrismaille committed Dec 20, 2023
1 parent c005653 commit dc3560c
Show file tree
Hide file tree
Showing 25 changed files with 385 additions and 367 deletions.
2 changes: 1 addition & 1 deletion .run/Migrate.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/example_app" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/example_google_app" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
Expand Down
3 changes: 2 additions & 1 deletion .run/Run Example App.run.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run Example App" type="Python.DjangoServer" factoryName="Django server">
<module name="django-google-sso" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
<env name="DJANGO_SETTINGS_MODULE" value="settings" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/example_app" />
<option name="WORKING_DIRECTORY" value="\\wsl.localhost\Ubuntu\home\chris\Projects\megalus\django-google-sso\example_google_app" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
Expand Down
18 changes: 1 addition & 17 deletions django_google_sso/checks/warnings.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import glob
import os

from django.core.checks import Tags, register
from django.core.checks.messages import Warning
from django.core.checks.templates import check_for_template_tags_with_the_same_name


def get_template_tag_names():
dir_path = os.path.dirname(__file__)
template_path = os.path.join(os.path.dirname(dir_path), "templatetags")
python_files = glob.glob(os.path.join(template_path, "*.py"))
names = [
os.path.basename(file).replace(".py", "")
for file in python_files
if not file.endswith("__init__.py")
]
return names


TEMPLATE_TAG_NAMES = get_template_tag_names()
TEMPLATE_TAG_NAMES = ["show_form", "sso_tags"]


@register(Tags.templates)
Expand Down
1 change: 0 additions & 1 deletion django_google_sso/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@


class Migration(migrations.Migration):

dependencies = [
('django_google_sso', '0001_initial'),
("django_google_sso", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name='googlessouser',
name='picture_url',
model_name="googlessouser",
name="picture_url",
field=models.URLField(max_length=2000),
),
]
18 changes: 13 additions & 5 deletions django_google_sso/static/django_google_sso/google_button.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
login-btn
---------------------------------
| -------------- |
| | btn-logo | btn-label |
| -------------- |
| -------------- |
| | btn-logo | btn-label |
| -------------- |
----------------------------------
*/

Expand All @@ -14,6 +14,8 @@
padding: 2px;
margin-bottom: 10px;
width: 100%;
height: 28px;
display: flex;
}

/* Google Login Button Hover */
Expand All @@ -24,15 +26,22 @@
/* Google Login Button Remove Decoration */
.google-login-btn a {
text-decoration: none;
width: 100%;
}

/* Google Login Button Logo Area */
.google-btn-logo {
display: flex;
justify-content: center;
align-content: center;
padding: 4px;
background-color: white;
height: 28px;
width: 28px;
}

.google-btn-logo img {
height: 28px;
width: 28px;
}

/* Google Login Button Label Area */
Expand All @@ -41,5 +50,4 @@
margin-top: -1px;
width: 100%;
text-align: center;
padding: 0 10px;
}
5 changes: 3 additions & 2 deletions django_google_sso/templatetags/sso_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.templatetags.static import static
from django.urls import reverse
from django.utils.translation import gettext
from loguru import logger

register = template.Library()

Expand Down Expand Up @@ -39,6 +40,6 @@ def define_sso_providers():
),
}
)
except ModuleNotFoundError:
pass
except Exception as e:
logger.error(f"Error importing {package_name}: {e}")
return sso_providers
Binary file modified docs/images/django_multiple_sso.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/model.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ GOOGLE_SSO_SCOPES = [ # Google default scope

You can change this scopes overriding the `GOOGLE_SSO_SCOPES` setting in your `settings.py` file. But if you ask the user
to authorize more scopes, this plugin will not save this additional data in the database. You will need to implement
your own logic to save this data, calling Google again. You can see a example [here](./how.md).
your own logic to save this data, calling Google again. You can see a example [here](./advanced.md).

!!! info "The main goal here is simplicity"
The main goal of this plugin is to be simple to use as possible. But it is important to ask the user **_once_** for the scopes.
Expand Down
40 changes: 32 additions & 8 deletions docs/multiple.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ package which you need to install and configure:

* [Django Google SSO](https://github.com/megalus/django-google-sso)
* [Django Microsoft SSO](https://github.com/megalus/django-microsoft-sso)
* [Django GitHub SSO](https://github.com/megalus/django-github-sso)

## Install the Packages
Install the packages you need:

```bash
pip install django-google-sso django-microsoft-sso
pip install django-google-sso django-microsoft-sso django-github-sso

# Optionally install Stela to handle .env files
pip install stela
Expand All @@ -25,8 +26,9 @@ To add this package in your Django Project, please modify the `INSTALLED_APPS` i
INSTALLED_APPS = [
# other django apps
"django.contrib.messages", # Need for Auth messages
"django_microsoft_sso", # First button in login page
"django_google_sso", # Second button in login page
"django_github_sso", # Will show as first button in login page
"django_google_sso",
"django_microsoft_sso",
]
```

Expand All @@ -43,6 +45,9 @@ GOOGLE_SSO_PROJECT_ID=999999999999

MICROSOFT_SSO_APPLICATION_ID=FOO
MICROSOFT_SSO_CLIENT_SECRET=BAZ

GITHUB_SSO_CLIENT_ID=BAR
GITHUB_SSO_CLIENT_SECRET=FOOBAR
```

### Setup Django URLs
Expand All @@ -54,12 +59,16 @@ from django.urls import include, path

urlpatterns += [
path(
"microsoft_sso/",
include("django_google_sso.urls", namespace="django_microsoft_sso"),
"github_sso/",
include("django_google_sso.urls", namespace="django_github_sso"),
),
path(
"google_sso/",
include("django_github_sso.urls", namespace="django_google_sso"),
),
path(
"microsoft_sso/",
include("django_microsoft_sso.urls", namespace="django_microsoft_sso"),
include("django_github_sso.urls", namespace="django_microsoft_sso"),
),
]
```
Expand All @@ -83,11 +92,26 @@ GOOGLE_SSO_CLIENT_ID = env.GOOGLE_SSO_CLIENT_ID
GOOGLE_SSO_PROJECT_ID = env.GOOGLE_SSO_PROJECT_ID
GOOGLE_SSO_CLIENT_SECRET = env.GOOGLE_SSO_CLIENT_SECRET
GOOGLE_SSO_ALLOWABLE_DOMAINS = ["contoso.net"]

# Django GitHub SSO
GITHUB_SSO_ENABLED = True
GITHUB_SSO_CLIENT_ID = env.GITHUB_SSO_CLIENT_ID
GITHUB_SSO_CLIENT_SECRET = env.GITHUB_SSO_CLIENT_SECRET
GITHUB_SSO_ALLOWABLE_ORGANIZATIONS = ["contoso"]
```

The login page will look like this:

![Django Login Page with Google and Microsoft SSO](../images/django_multiple_sso.png)
![Django Login Page with Google and Microsoft SSO](images/django_multiple_sso.png)

!!! tip "You can hide the login form"
If you want to show only the SSO buttons, you can hide the login form using the `SSO_SHOW_FORM_ON_ADMIN_PAGE` setting.

```python
# settings.py

SSO_SHOW_FORM_ON_ADMIN_PAGE = False
```

### The Django E003/W003 Warning
If you are using both **Django Google SSO** and **Django Microsoft SSO**, you will get the following warning:
Expand All @@ -111,6 +135,6 @@ run the original check, but will not raise the warning for the Django SSO packag
```python
# settings.py

SILENCED_SYSTEM_CHECKS = ["templates.E003"] # Will silence original check
SILENCED_SYSTEM_CHECKS = ["templates.E003"] # Will silence the original check
SSO_USE_ALTERNATE_W003 = True # Will run alternate check
```
2 changes: 2 additions & 0 deletions docs/thanks.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ I really hope this project can make your life a little easier.
Please feel free to check our other projects:

* [stela](https://github.com/megalus/stela): Easily manage project settings and secrets in any python project.
* [django-google-sso](https://github.com/megalus/django-google-sso): A Django app to enable Single Sign-On with Google Accounts.
* [django-microsoft-sso](https://github.com/megalus/django-microsoft-sso): A Django app to enable Single Sign-On with Microsoft 365 Accounts.
* [django-github-sso](https://github.com/megalus/django-github-sso): A Django app to enable Single Sign-On with GitHub Accounts.

## Donating

Expand Down
4 changes: 2 additions & 2 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
If you log out from Google, the Django user will not be logged out automatically - his user session is valid up to
1 hour, or the time defined, in seconds, in `GOOGLE_SSO_SESSION_COOKIE_AGE`. You can use the `GOOGLE_SSO_SAVE_ACCESS_TOKEN`
to save the access token generated during user login, and use it to check if the user status in Google (inside a
Middleware, for example). Please check the [Example App](https://github.com/megalus/django-google-sso/tree/main/example_app)
Middleware, for example). Please check the [Example App](https://github.com/megalus/django-google-sso/tree/main/example_google_app)
for more details.

### Example App

To test this library please check the `Example App` provided [here](https://github.com/megalus/django-google-sso/tree/main/example_app).
To test this library please check the `Example App` provided [here](https://github.com/megalus/django-google-sso/tree/main/example_google_app).

### Not working?

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 16 additions & 16 deletions example_app/asgi.py → example_google_app/asgi.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""
ASGI config for example_app project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_app.settings")

application = get_asgi_application()
"""
ASGI config for example_google_app project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_google_app.settings")

application = get_asgi_application()
File renamed without changes.
44 changes: 22 additions & 22 deletions example_app/manage.py → example_google_app/manage.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_app.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example_google_app.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
Loading

0 comments on commit dc3560c

Please sign in to comment.