-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Custom account email verification through adapter #1946 #3648
base: main
Are you sure you want to change the base?
Changes from 1 commit
7c0b754
91dce00
24d2ca8
a9c19db
efe1169
3da30bc
8e61e0e
0ed5a9e
c7c06ea
d95f449
80f3049
a7e5452
fb79e68
491c3b3
67ddd43
3d9a847
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from allauth.socialaccount.adapter import get_adapter | ||
from allauth.account.models import EmailAddress | ||
from allauth.socialaccount import app_settings | ||
from allauth.socialaccount.providers.base import AuthAction, ProviderAccount | ||
|
@@ -58,14 +59,16 @@ class AuthentiqProvider(OAuth2Provider): | |
account_class = AuthentiqAccount | ||
|
||
def get_scope(self, request): | ||
adapter = get_adapter() | ||
scope = set(super(AuthentiqProvider, self).get_scope(request)) | ||
scope.add("openid") | ||
|
||
if Scope.EMAIL in scope: | ||
modifiers = "" | ||
if app_settings.EMAIL_REQUIRED: | ||
modifiers += "r" | ||
if app_settings.EMAIL_VERIFICATION: | ||
#TODO: How to get user email here for get_email_verification_method ? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How can I get user's email in this method to pass it to get_email_verification_method ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is called to get a list of scopes to ask permission for as part of the OAuth handshake. So, at this point in time you do not know what user is going to be authenticated, yet. |
||
if adapter.get_email_verification_method(): | ||
modifiers += "s" | ||
if modifiers: | ||
scope.add(Scope.EMAIL + "~" + modifiers) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we have a
Login
class representing the current login, I think it is more useful to base this method on an instance of that. See:https://github.com/pennersr/django-allauth/blob/main/allauth/account/utils.py#L158
So, for that to happen, I think we need to:
email_verification=app_settings.EMAIL_VERIFICATION
) is passed, passNone
. Then, inside the__init__
ofLogin
, when the email verification is not explicitly set to a value, call this adapter method.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for reviewing I'll work on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In assess_unique_email method https://github.com/pennersr/django-allauth/blob/main/allauth/account/utils.py#L496
We only have access to email not the Login instance as it is called before we complete signup.
Is it a good idea to keep both login and email ? or login can be None in this scenario ?