-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
141 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Register your models here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class GslOidcConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "gsl_oidc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from logging import getLogger | ||
|
||
import requests | ||
from mozilla_django_oidc.auth import ( | ||
OIDCAuthenticationBackend as MozillaOIDCAuthenticationBackend, | ||
) | ||
|
||
logger = getLogger(__name__) | ||
|
||
|
||
class OIDCAuthenticationBackend(MozillaOIDCAuthenticationBackend): | ||
def get_userinfo(self, access_token, id_token, payload): | ||
# Surcharge de la récupération des informations utilisateur: | ||
# le décodage JSON du contenu JWT pose problème avec ProConnect | ||
# qui le retourne en format JWT (content-type: application/jwt) | ||
# d'où ce petit hack. | ||
# Inspiré de : https://github.com/numerique-gouv/people/blob/b637774179d94cecb0ef2454d4762750a6a5e8c0/src/backend/core/authentication/backends.py#L47C1-L47C57 | ||
user_response = requests.get( | ||
self.OIDC_OP_USER_ENDPOINT, | ||
headers={"Authorization": "Bearer {0}".format(access_token)}, | ||
verify=self.get_settings("OIDC_VERIFY_SSL", True), | ||
timeout=self.get_settings("OIDC_TIMEOUT", None), | ||
proxies=self.get_settings("OIDC_PROXY", None), | ||
) | ||
user_response.raise_for_status() | ||
|
||
try: | ||
# cas où le type du token JWT est `application/json` | ||
return user_response.json() | ||
except requests.exceptions.JSONDecodeError: | ||
# sinon, on présume qu'il s'agit d'un token JWT au format `application/jwt` | ||
# comme c'est le cas pour ProConnect. | ||
return self.verify_token(user_response.text) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your views here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters