Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vgrange/peamu #126

Merged
merged 13 commits into from May 27, 2020
Merged

vgrange/peamu #126

merged 13 commits into from May 27, 2020

Conversation

dejafait
Copy link
Contributor

@dejafait dejafait commented Apr 9, 2020

TODO Vermeer

  • matomo post MEP

La code review PE Connect est ouverte, merci de la faire commit par commit svp. Il y a 3 petits et 1 gros commit.

Vous pouvez directement tester en recette jetable https://review-vgrange-peamu.cleverapps.io/

Commentaire du principal commit dupliqué ci-dessous:

PE Connect aka PEAMU is based on OpenID Connect (OIDC).
Note that OpenID Connect (OIDC) is *not* the same as OpenID.

PEAMU acronym is used as it is less ambiguous than PEAM, which does not
explicitely state if we are talking about PEAM Users of PEAM Enterprise.

This code is heavily inspired by official Google provider, also using OIDC:
https://github.com/pennersr/django-allauth/tree/master/allauth/socialaccount/providers/google

PEAMU redirect_uri works with port 8080 but not 8000 nor 5000,
and works only with `localhost` and not `0.0.0.0`.
These new constraints were implemented by PEAMU during March 2020.
Thus we have to use localhost:8080 for our local dev
instead of the former 0.0.0.0:8000 sorry! ¯\_(ツ)_/¯

Disable annoying PIN code in local dev debugger.

Refactor frontend login page into 3 variants for our 3 user roles.
Job seeker can PE Connect either from login page or from signup page.

More pages have been implemented:
1) login_cancelled.html which happens when user clicks "Cancel" on the
"Mire de connexion PE".
2) signup.html used when PEAMU user account is not valid yet.
See explanation in the template for more information.
3) authentication_error.html which is never supposed to be visible.

8 extra API PE Connect are prepared but not used yet,
as our 8 contracts have not been validated yet.

Screenshots :

image

image

image

image

image

image

edge cases:

image

image

@dejafait dejafait force-pushed the vgrange/peamu branch 4 times, most recently from dc1208f to 8bd6546 Compare April 10, 2020 16:05
@dejafait dejafait force-pushed the vgrange/peamu branch 2 times, most recently from c4bb5f7 to 94c885e Compare April 15, 2020 13:09
@ikarius
Copy link
Contributor

ikarius commented Apr 15, 2020

Ça à l'air bien cool.
Une remarque, si on merge la PR 111 (new prescripteurs) avant, le path pour l'inscription d'un nouveau prescripteur ne sera plus signup/prescriber mais signup/select_prescriber_type

@github-actions
Copy link

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@github-actions
Copy link

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@dejafait dejafait force-pushed the vgrange/peamu branch 3 times, most recently from 4632629 to 96bd03b Compare May 15, 2020 12:09
@celine-m-s celine-m-s self-requested a review May 18, 2020 15:11
<a href="https://www.pole-emploi.fr">
<button class="btn btn-primary">
{% trans "S'identifier chez Pôle emploi pour valider son compte" %}
{% trans "Veuillez retrouver l'email &laquo; <i>Confirmation de votre adresse électronique</i> &raquo; que Pôle emploi vous a envoyé le jour de la création de votre compte et y cliquer sur le lien &laquo; <i>Je confirme mon adresse électronique</i> &raquo;." %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici tu peux utiliser un {% blocktrans %} si tu veux éviter les &laquo;.

Copy link
Contributor

@kemar kemar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presque LGTM mais j'aimerais comprendre certains changements de ports. Le reste est minime et ne pose pas de problème à court terme, à implémenter si tu le juges nécessaire. Chouette boulot !

# https://www.emploi-store-dev.fr/portail-developpeur/catalogueapi
# Note that the `EMPLOI_STORE` naming below is incorrect,
# as the Emploi Store is a totally different beast than the ESD.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour moi ce commentaire est source de confusion.

Si le nom te semble incorrect alors il faut : soit le changer, soit accepter de vivre avec :)

Copy link
Contributor Author

@dejafait dejafait May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ouais ça me faisait un peu peur de le changer car il fallait aller triturer dans la conf CC. Mais maintenant que je connais mieux je vais le faire.

C'est un peu tricky tout de même pour changer sans coupure. Dans la conf CC il faut dupliquer les variables, puis MEP, puis enlever les anciennes variables. Pour staging et pour prod.

Will do.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je vais en profiter pour remplacer "Emploi Store Dev" par "ESD" partout. Shorter is nicer.

API_EMPLOI_STORE_KEY = os.environ["API_EMPLOI_STORE_KEY"]
API_EMPLOI_STORE_SECRET = os.environ["API_EMPLOI_STORE_SECRET"]
API_EMPLOI_STORE_AUTH_BASE_URL = "https://entreprise.pole-emploi.fr"
API_EMPLOI_STORE_BASE_URL = "https://api.emploi-store.fr/partenaire"

# PE Connect aka PEAMU - technically one of ESD's APIs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait je vois PEAMU écrit partout dans la base de code mais je ne sais pas ce que ça signifie.

Perso je connais PEAM pour "Pôle Emploi Access Management" tel que mentionné dans la doc.

Je suppose que le U vient pour "User" ? Ça serait pas mal de le mentionner une fois en commentaire dans les settings.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nouveau commentaire :

# PE Connect aka PEAMU - technically one of ESD's APIs.
# PEAM stands for Pôle Emploi Access Management.
# Technically there are two PEAM distinct systems:
# - PEAM "Entreprise", PEAM-E or PEAME for short.
# - PEAM "Utilisateur", PEAM-U or PEAMU for short.
# To avoid confusion between the two when contacting ESD support,
# we get the habit to always explicitely state that we are using PEAM*U*.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pour mémoire j'ai pris cette habitude suite à une grosse galère avec le support ESD pour un souci PE Connect LBB. Après m'avoir baladé d'interlocuteur en interlocuteur, je me suis pris un "Ah bon c'est pas PEAM Entreprise que vous utilisez?". Never again. PEAMU.

@@ -34,7 +34,7 @@ services:
- .:/app
restart: always
ports:
- "${DJANGO_PORT_ON_DOCKER_HOST:-8000}:8000"
- "${DJANGO_PORT_ON_DOCKER_HOST:-8080}:8080"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne comprends pas cette modif et du coup j'ai l'impression que tu n'as pas bien compris non plus.

J'explique : la première valeur est configurable et opère sur la machine hôte (ta machine de dev) via une variable d'environnement à la convenance du développeur avec DJANGO_PORT_ON_DOCKER_HOST. La seconde valeur n'a pas besoin d'être modifiée car elle concerne le port à l'intérieur du conteneur Docker.

Est-ce que c'était une incompréhension ou il y a une vraie raison pour ce changement ?

Copy link
Contributor Author

@dejafait dejafait May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C'est pas plus simple de garder le même numéro de port pour les deux? Sinon on va se mélanger entre 8000 et 8080. Avant PEAMU c'était le même port 8000 pour les deux, on se posait pas la question.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alors laisse 8000 car c'est le port par défaut.

Si tu as besoin d'un 8080 sur ta machine alors c'est un réglage spécifique pour toi et tu dois utiliser le mapping de ports grâce à DJANGO_PORT_ON_DOCKER_HOST.

Copy link
Contributor Author

@dejafait dejafait May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ce n'est pas un réglage/tuning perso, c'est nécéssaire pour faire fonctionner PEAMU en local dev, qui plante pour une redirect_uri en localhost 8000 mais passe avec un localhost 8080. Me demande pas pourquoi, c'est une maj cryptique de sécu côté PEAMU qui date de mars 2020 et qui a été bien pénible à investiguer et solutionner.

Du coup en forcant et passant tout le monde à 8080, j'évite une galère monumentale aux autres devs qui veulent faire tourner PEAMU en local.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok alors je comprends qu'il y a un motif légitime. C'est bizarre que ça te force aussi à modifier le port à l'intérieur du Docker cela dit… Bref, compris !

Copy link
Contributor Author

@dejafait dejafait May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je ne suis pas obligé de modifier le port à l'intérieur du docker, j'aurai pu le laisser à 8000. Mais imagine que tu es un nouveau dev qui arrive sur le projet, tu vas être "wtf pourquoi c'est deux ports différents à l'extérieur et à l'intérieur du docker, pourquoi pas juste 8080 partout?".

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui ok j'ai compris mais je peux pas t'expliquer Docker plus que ce que j'ai déjà fait. S'il y a un WTF c'est juste que tu n'as pas compris ton archi de dev !

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmm apparemment il n'y a que moi que ça pertube d'utiliser deux numéros de port différents là où on pourrait utiliser le même pour plus de simplicité, je rollbacke donc le port interne du container à la valeur par défaut de 8000. Garder la valeur par défaut là où c'est possible est plus important que mon pinaillage.

#
# Disable for you the annoying PIN security prompt on the web
# debugger. For local dev only of course!
django-admin runserver_plus 0.0.0.0:8080 --nopin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention car là tu es dans ton Docker. Donc pour parler au monde extérieur tu dois bien utiliser 0.0.0.0 pour écouter sur toutes les interfaces réseau disponibles. En laissant 127.0.0.1 ou localhost tu te cantonnes à communiquer avec le même hôte, donc ici ton conteneur Docker.

Idem, pas besoin de ce changement de port à l'intérieur du conteneur Docker qui ne concerne pas le monde extérieur.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. C'est juste dommage de pas avoir trouvé une solution pour que l'URL ici :
image

soit la bonne.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait l'URL est bonne puisque c'est l'IP 0.0.0.0 du conteneur Docker qui est exposée. Il faut juste comprendre que c'est celle du Docker et que tu l'attaques depuis l'hôte via un mapping de port.

if self.access_token_method == "GET":
params = data
data = None
# TODO: Proper exception handling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tu peux mettre un resp.raise_for_status() ici peut-être ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bof. L'idée en surchargeant get_access_token est juste d'injecter le strict nécéssaire params = {"realm": "/individu"} et de ne surtout pas toucher au code de la dépendance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je dis ça en rapport au commentaire :

TODO: Proper exception handling

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je me suis peut-être mal exprimé. Ce commentaire vient de la dépendance : https://github.com/pennersr/django-allauth/blob/6a6d3c618ab018234dde8701173093274710ee0a/allauth/socialaccount/providers/oauth2/client.py#L65

Ta suggestion a plutôt sa place comme une PR sur django-allauth non?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah compris, du coup est-ce qu'il faut vraiment conserver verbatim le code de la dépendance quitte à créer la confusion à la lecture ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je vais juste virer le commentaire confusant, ça mange pas de pain.

@@ -12,7 +12,7 @@

Vous pouvez personnaliser la configuration Compose en créant [un fichier `.env`](https://docs.docker.com/compose/env-file/) au même niveau que le fichier `README.md`, puis y configurer les variables d'environnement suivantes :

DJANGO_PORT_ON_DOCKER_HOST=8000
DJANGO_PORT_ON_DOCKER_HOST=8080
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, pas de problème avec la modification de ce port car il concerne un port sur la machine de dev et pas dans le conteneur Docker.

@@ -119,6 +119,16 @@ def get_eligibility_diagnosis(self):
"author", "author_siae", "author_prescriber_organization"
).latest("-created_at")

@property
def is_peamu(self):
return self.socialaccount_set.exists()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ici la fonction ne fait pas ce qu'elle annonce, tu devrais pouvoir filtrer sur provider ou quelque chose comme ça pour être certain de taper dans du PE Connect et ne pas remonter autre chose si un jour on rajoute Facebook connect ou autre.

Astuce bonus : tu peux utiliser cached_property.

def peamu_id_token(self):
if not self.is_peamu:
return None
return self.socialaccount_set.get().extra_data["id_token"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem pour le filtre PE Connect.

PE Connect aka PEAMU is based on OpenID Connect (OIDC).
Note that OpenID Connect (OIDC) is *not* the same as OpenID.

PEAMU acronym is used as it is less ambiguous than PEAM, which does not
explicitely state if we are talking about PEAM Users of PEAM Enterprise.

This code is heavily inspired by official Google provider, also using OIDC:
https://github.com/pennersr/django-allauth/tree/master/allauth/socialaccount/providers/google

PEAMU redirect_uri works with port 8080 but not 8000 nor 5000,
and works only with `localhost` and not `0.0.0.0`.
These new constraints were implemented by PEAMU during March 2020.
Thus we have to use localhost:8080 for our local dev
instead of the former 0.0.0.0:8000 sorry! ¯\_(ツ)_/¯

Disable annoying PIN code in local dev debugger.

Refactor frontend login page into 3 variants for our 3 user roles.
Job seeker can PE Connect either from login page or from signup page.

More pages have been implemented:
1) login_cancelled.html which happens when user clicks "Cancel" on the
"Mire de connexion PE".
2) signup.html used when PEAMU user account is not valid yet.
See explanation in the template for more information.
3) authentication_error.html which is never supposed to be visible.

8 extra API PE Connect are prepared but not used yet,
as our 8 contracts have not been validated yet.
@github-actions
Copy link

🥁 La recette jetable est prête ! 👉 Je veux tester cette PR !

@dejafait dejafait merged commit e8555c9 into master May 27, 2020
@dejafait dejafait deleted the vgrange/peamu branch May 27, 2020 12:54
tonial added a commit that referenced this pull request Sep 2, 2022
We use 8080 since PR #126, because of PEAMU.
But we can now use PEAMU with the port 8000, so there's no need to use a
different port from django's default port.

Also : PEAMU does not allow localhost as base url for the callback uri,
but 127.0.0.1 is fine. Therefore I changed the dev FQDN to allow us to
use PEAMU without having to update the dev settings.
tonial added a commit that referenced this pull request Sep 2, 2022
We use 8080 since PR #126, because of PEAMU.
But we can now use PEAMU with the port 8000, so there's no need to use a
different port from django's default port.

Also : PEAMU does not allow localhost as base url for the callback uri,
but 127.0.0.1 is fine. Therefore I changed the dev FQDN to allow us to
use PEAMU without having to update the dev settings.
tonial added a commit that referenced this pull request Sep 5, 2022
We use 8080 since PR #126, because of PEAMU.
But we can now use PEAMU with the port 8000, so there's no need to use a
different port from django's default port.

Also : PEAMU does not allow localhost as base url for the callback uri,
but 127.0.0.1 is fine. Therefore I changed the dev FQDN to allow us to
use PEAMU without having to update the dev settings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants