goauthentik / goauthentik/authentik
Allow login using external IdP only if the email is already assigned to a user
- Dominant language
- Python
- Stars
- 25.6k
- Forks
- 2k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 644
Description
**Describe your question/**
Hello everyone, I am trying to my Authentik setup with some external IdP and everything works as expected.
The idea now is restrict the access to only authorized users and I would like to authorize users by manually creating that user (with username and email already defined by me). What I want to achieve is allow login using external IdP that should be automatically connected with that existing users. Of course, if no user with that specific email is in the database, the login should fail.
What I tried is update the policy `default-source-enrollment-if-sso` with the following code but I always get the prompt to set the username when I try to login with an email from an external IdP that is already linked to an existing account
```
email = request.context["prompt_data"]["email"]
# look for a user with the specific email
check_user = ak_user_by(email=email)
if check_user is not None:
return True
ak_message("User is not allowed.")
return False
```
**Relevant info**
Username is immutable in my setup and email must be unique.
Authentik version: 2024.2
**Version and Deployment (please complete the following information):**
- authentik version: 2024.2
- Deployment: deployed on TrueNas using TrueCharts
Contributor guide
Assessment
This issue has not been assessed yet.