Email Verification Protocol · Python
Verify email addresses without sending an email
With the Email Verification Protocol, the browser brings a token signed by the user's email provider. PyEVP verifies it on your Python server: no confirmation email, no code to copy.
How it works
-
The browser asks
The browser asks the user's email provider for a token.
-
The provider vouches
The provider vouches for the email address by signing the token.
-
Your server verifies
Your server verifies the token with PyEVP.
See the compatibility guide for browser support and deployment requirements.
Getting started
pip install "pyevp[dns,httpx2]"Framework examples
Each snippet is cut from the example code in the repository, so it stays in sync with what is tested.
FastAPI
try:
# Takes the token's nonce from the session, whether or not it verifies.
result = await verifier.verify_submission(
evt, nonces=SessionNonces(request.session), email=email
)
except EVPError as exc:
raise HTTPException(status_code=400, detail={"code": exc.code}) from exc
if result is None:
# No token: fall back to sending a confirmation email, as before EVP.
return {"email": email, "verified": False}
return {"email": result.email, "verified": True, "issuer": result.issuer}
Flask
verifier: Verifier = current_app.extensions["evp_verifier"]
email = request.form["email"]
try:
# Takes the token's nonce from the session, whether or not it verifies.
result = verifier.verify_submission(
request.form.get("evt"), nonces=SessionNonces(session), email=email
)
except EVPError as exc:
return {"error": {"code": exc.code}}, 400
if result is None:
# No token: fall back to sending a confirmation email, as before EVP.
return {"email": email, "verified": False}
return {"email": result.email, "verified": True, "issuer": result.issuer}
Django
def signup(request: HttpRequest) -> HttpResponse:
form = SignupForm(request.POST or None)
if request.method == "POST" and form.is_valid():
email = form.cleaned_data["email"]
try:
result = verify_request(request, get_verifier(), email=email)
except EVPError as exc:
return JsonResponse({"error": {"code": exc.code}}, status=400)
if result is None:
# No token: fall back to sending a confirmation email, as before EVP.
return JsonResponse({"email": email, "verified": False})
return JsonResponse({"email": result.email, "verified": True, "issuer": result.issuer})
# {% evp_token_input %} in the template puts a nonce in the session.
return render(request, "signup.html", {"form": form})