PyEVP 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyevp-0.1.0/LICENSE +21 -0
- pyevp-0.1.0/PKG-INFO +171 -0
- pyevp-0.1.0/README.md +128 -0
- pyevp-0.1.0/pyproject.toml +131 -0
- pyevp-0.1.0/pyproject.toml.orig +109 -0
- pyevp-0.1.0/src/pyevp/__init__.py +47 -0
- pyevp-0.1.0/src/pyevp/__main__.py +28 -0
- pyevp-0.1.0/src/pyevp/_email.py +65 -0
- pyevp-0.1.0/src/pyevp/_httpsig.py +284 -0
- pyevp-0.1.0/src/pyevp/_jose.py +145 -0
- pyevp-0.1.0/src/pyevp/_sf.py +406 -0
- pyevp-0.1.0/src/pyevp/adapters/__init__.py +4 -0
- pyevp-0.1.0/src/pyevp/adapters/_doh.py +92 -0
- pyevp-0.1.0/src/pyevp/adapters/_fetch.py +86 -0
- pyevp-0.1.0/src/pyevp/adapters/_http.py +38 -0
- pyevp-0.1.0/src/pyevp/adapters/dnspython.py +79 -0
- pyevp-0.1.0/src/pyevp/adapters/doh.py +130 -0
- pyevp-0.1.0/src/pyevp/adapters/httpx.py +147 -0
- pyevp-0.1.0/src/pyevp/adapters/urllib.py +170 -0
- pyevp-0.1.0/src/pyevp/cache.py +83 -0
- pyevp-0.1.0/src/pyevp/cli/__init__.py +348 -0
- pyevp-0.1.0/src/pyevp/contrib/__init__.py +4 -0
- pyevp-0.1.0/src/pyevp/contrib/django/__init__.py +306 -0
- pyevp-0.1.0/src/pyevp/contrib/django/apps.py +17 -0
- pyevp-0.1.0/src/pyevp/contrib/django/issuer.py +314 -0
- pyevp-0.1.0/src/pyevp/contrib/django/migrations/0001_initial.py +17 -0
- pyevp-0.1.0/src/pyevp/contrib/django/migrations/__init__.py +0 -0
- pyevp-0.1.0/src/pyevp/contrib/django/models.py +14 -0
- pyevp-0.1.0/src/pyevp/contrib/django/templatetags/__init__.py +0 -0
- pyevp-0.1.0/src/pyevp/contrib/django/templatetags/pyevp.py +32 -0
- pyevp-0.1.0/src/pyevp/core.py +321 -0
- pyevp-0.1.0/src/pyevp/diagnostics.py +182 -0
- pyevp-0.1.0/src/pyevp/discovery.py +144 -0
- pyevp-0.1.0/src/pyevp/errors.py +80 -0
- pyevp-0.1.0/src/pyevp/issuer/__init__.py +39 -0
- pyevp-0.1.0/src/pyevp/issuer/core.py +413 -0
- pyevp-0.1.0/src/pyevp/issuer/errors.py +99 -0
- pyevp-0.1.0/src/pyevp/issuer/fedcm.py +44 -0
- pyevp-0.1.0/src/pyevp/issuer/keys.py +140 -0
- pyevp-0.1.0/src/pyevp/issuer/profile.py +96 -0
- pyevp-0.1.0/src/pyevp/nonce.py +25 -0
- pyevp-0.1.0/src/pyevp/observability.py +89 -0
- pyevp-0.1.0/src/pyevp/ports.py +54 -0
- pyevp-0.1.0/src/pyevp/profile.py +153 -0
- pyevp-0.1.0/src/pyevp/py.typed +0 -0
- pyevp-0.1.0/src/pyevp/replay.py +69 -0
- pyevp-0.1.0/src/pyevp/testing.py +343 -0
- pyevp-0.1.0/src/pyevp/token.py +135 -0
- pyevp-0.1.0/src/pyevp/types.py +37 -0
- pyevp-0.1.0/src/pyevp/verifier.py +486 -0
pyevp-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Gakuto Furuya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
pyevp-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: PyEVP
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python library for the Email Verification Protocol (EVP): verify tokens as a relying party, or issue them for your own email domains
|
|
5
|
+
Keywords: email,verification,evp,sd-jwt,jose,authentication
|
|
6
|
+
Author: Gakuto Furuya
|
|
7
|
+
Author-email: Gakuto Furuya <g.furuya@gaato.net>
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
+
Classifier: Topic :: Security
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Dist: idna>=3.7
|
|
22
|
+
Requires-Dist: joserfc>=1.7
|
|
23
|
+
Requires-Dist: pyevp[dns,httpx2,django,cli] ; extra == 'all'
|
|
24
|
+
Requires-Dist: pyevp[dns,httpx2] ; extra == 'cli'
|
|
25
|
+
Requires-Dist: typer>=0.27 ; extra == 'cli'
|
|
26
|
+
Requires-Dist: django>=4.2 ; extra == 'django'
|
|
27
|
+
Requires-Dist: dnspython>=2.7 ; extra == 'dns'
|
|
28
|
+
Requires-Dist: anyio>=4.5 ; extra == 'httpx'
|
|
29
|
+
Requires-Dist: httpx>=0.28 ; extra == 'httpx'
|
|
30
|
+
Requires-Dist: anyio>=4.5 ; extra == 'httpx2'
|
|
31
|
+
Requires-Dist: httpx2>=2.13 ; extra == 'httpx2'
|
|
32
|
+
Requires-Python: >=3.11
|
|
33
|
+
Project-URL: Documentation, https://docs.pyevp.dev/
|
|
34
|
+
Project-URL: Repository, https://github.com/gaato/pyevp
|
|
35
|
+
Project-URL: Changelog, https://github.com/gaato/pyevp/blob/main/CHANGELOG.md
|
|
36
|
+
Provides-Extra: all
|
|
37
|
+
Provides-Extra: cli
|
|
38
|
+
Provides-Extra: django
|
|
39
|
+
Provides-Extra: dns
|
|
40
|
+
Provides-Extra: httpx
|
|
41
|
+
Provides-Extra: httpx2
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
|
|
44
|
+
# PyEVP
|
|
45
|
+
|
|
46
|
+
[](https://docs.pyevp.dev/en/latest/)
|
|
47
|
+
[](https://github.com/gaato/pyevp/actions/workflows/ci.yml)
|
|
48
|
+
[](https://github.com/gaato/pyevp/actions/workflows/drift.yml)
|
|
49
|
+
[](https://github.com/dickhardt/email-verification)
|
|
50
|
+

|
|
51
|
+
[](https://github.com/astral-sh/ty)
|
|
52
|
+
[](https://github.com/gaato/pyevp/blob/main/LICENSE)
|
|
53
|
+
[](https://deepwiki.com/gaato/pyevp)
|
|
54
|
+
|
|
55
|
+
[日本語](https://github.com/gaato/pyevp/blob/main/README.ja.md)
|
|
56
|
+
|
|
57
|
+
Python library for the **Email Verification Protocol** (EVP): verify tokens as a relying party,
|
|
58
|
+
or issue them for your own email domains. With EVP, the browser obtains a token from the user's
|
|
59
|
+
email provider proving they control an address, and your server verifies it, with no confirmation
|
|
60
|
+
email round-trip.
|
|
61
|
+
|
|
62
|
+
**Documentation: <https://docs.pyevp.dev/>**
|
|
63
|
+
|
|
64
|
+
> **Status: alpha.** The protocol ([draft-hardt-email-verification], [WICG Email Verification API])
|
|
65
|
+
> and browser support (Chrome origin trial) are still changing. This library isolates every
|
|
66
|
+
> moving part in a versioned `Profile` so it can follow along.
|
|
67
|
+
|
|
68
|
+
[draft-hardt-email-verification]: https://github.com/dickhardt/email-verification
|
|
69
|
+
[WICG Email Verification API]: https://github.com/WICG/email-verification
|
|
70
|
+
|
|
71
|
+
## Install
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
pip install "pyevp[dns,httpx2]" # core + the DNS and HTTP adapters
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The core depends only on [joserfc] and idna. DNS and HTTP are pluggable; `[dns,httpx2]` installs
|
|
78
|
+
the default adapters used by `Verifier.default()`. `[all]` installs every optional dependency,
|
|
79
|
+
including the Django integration and the command line.
|
|
80
|
+
|
|
81
|
+
The HTTP adapters work with [httpx2] (pydantic's maintained fork of httpx) or httpx and prefer
|
|
82
|
+
httpx2 when both are installed, so `pip install "pyevp[dns,httpx]"` works too. A client from either
|
|
83
|
+
library can be passed explicitly, e.g. `HttpxFetcher(httpx.Client(...))`.
|
|
84
|
+
|
|
85
|
+
[httpx2]: https://github.com/pydantic/httpx2
|
|
86
|
+
|
|
87
|
+
[joserfc]: https://jose.authlib.org/
|
|
88
|
+
|
|
89
|
+
## How it works
|
|
90
|
+
|
|
91
|
+
1. Render a form with a fresh nonce stored in the user's session:
|
|
92
|
+
|
|
93
|
+
```html
|
|
94
|
+
<input type="email" name="email" autocomplete="email">
|
|
95
|
+
<input type="hidden" name="evt" autocomplete="email-verification-token" nonce="{{ nonce }}">
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
2. When the user picks an address, the browser fills `evt` with `<EVT>~<KB-JWT>`.
|
|
99
|
+
3. On submit, verify it:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from pyevp import Verifier, EVPError, generate_nonce
|
|
103
|
+
|
|
104
|
+
verifier = Verifier.default(audience="https://example.com") # your origin
|
|
105
|
+
|
|
106
|
+
try:
|
|
107
|
+
result = verifier.verify(form["evt"], nonce=session.pop("evp_nonce"), email=form["email"])
|
|
108
|
+
except EVPError as exc:
|
|
109
|
+
... # exc.code is an ErrorCode, e.g. "nonce_mismatch"; fall back to email confirmation
|
|
110
|
+
else:
|
|
111
|
+
result.email, result.issuer # verified
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
`AsyncVerifier` has the same API with `await verifier.verify(...)`.
|
|
115
|
+
|
|
116
|
+
Verification checks the key-binding JWT (audience, nonce, freshness, `sd_hash`, holder signature)
|
|
117
|
+
before doing any I/O. It then discovers the issuer from DNS (`_email-verification.<domain>`
|
|
118
|
+
TXT `iss=…`), fetches its metadata and JWKS (cached), and verifies the issuer's signature. Only
|
|
119
|
+
hosts derived from DNS are ever contacted, never hosts named in the token. Before connecting, the
|
|
120
|
+
default fetchers also check that the host resolves only to public addresses; see
|
|
121
|
+
[private networks](https://docs.pyevp.dev/en/latest/guides/transport.html#ssrf) for what this check
|
|
122
|
+
does not catch.
|
|
123
|
+
|
|
124
|
+
Every rejected token raises an `EVPError` with an `ErrorCode`. The safe default is to fall back to your existing
|
|
125
|
+
verification flow; the [error table](https://docs.pyevp.dev/en/latest/quickstart.html#handle-failures) tells which codes
|
|
126
|
+
the user can retry and which point at your configuration.
|
|
127
|
+
|
|
128
|
+
## Command line
|
|
129
|
+
|
|
130
|
+
`pyevp[cli]` installs a `pyevp` command for relying-party developers and operators, and for
|
|
131
|
+
issuer operators checking their own setup. It runs without installing anything into your project:
|
|
132
|
+
|
|
133
|
+
```sh
|
|
134
|
+
uvx --from "pyevp[cli]" pyevp discover gmail.com # DNS record, metadata, keys vs. profile
|
|
135
|
+
pbpaste | uvx --from "pyevp[cli]" pyevp inspect # decode a token offline (no signature checks)
|
|
136
|
+
uvx --from "pyevp[cli]" pyevp verify "$TOKEN" --audience https://example.com --nonce "$NONCE"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
See the [CLI guide](https://docs.pyevp.dev/en/latest/guides/cli.html) for every command and option.
|
|
140
|
+
|
|
141
|
+
## More
|
|
142
|
+
|
|
143
|
+
- [Frameworks](https://docs.pyevp.dev/en/latest/guides/frameworks.html): FastAPI, Flask, fastapi-users, AuthX and Django
|
|
144
|
+
- [Testing your application](https://docs.pyevp.dev/en/latest/guides/testing.html): `FakeIssuer` and `FakeBrowser`, no network needed
|
|
145
|
+
- [Replay protection](https://docs.pyevp.dev/en/latest/guides/replay.html), [logging and metrics](https://docs.pyevp.dev/en/latest/guides/observability.html)
|
|
146
|
+
- [DNS, HTTP and caching](https://docs.pyevp.dev/en/latest/guides/transport.html): DNS over HTTPS, a standard-library-only setup, private networks
|
|
147
|
+
- [Profiles](https://docs.pyevp.dev/en/latest/concepts.html#profiles): how PyEVP follows a protocol that is still changing
|
|
148
|
+
- [Running an issuer](https://docs.pyevp.dev/en/latest/guides/issuer-operations.html) for your own mail domains
|
|
149
|
+
- [Compatibility policy](https://docs.pyevp.dev/en/latest/compatibility.html)
|
|
150
|
+
|
|
151
|
+
## Examples
|
|
152
|
+
|
|
153
|
+
Each example is a standalone project with its own tests:
|
|
154
|
+
|
|
155
|
+
- [`examples/fastapi`](https://github.com/gaato/pyevp/blob/main/examples/fastapi/app.py): FastAPI with session nonces
|
|
156
|
+
- [`examples/flask`](https://github.com/gaato/pyevp/blob/main/examples/flask/app.py): the same flow with the synchronous `Verifier`
|
|
157
|
+
- [`examples/fastapi_spa`](https://github.com/gaato/pyevp/blob/main/examples/fastapi_spa/app.py): a JSON API for a single-page app, without server sessions, with password recovery
|
|
158
|
+
- [`examples/fastapi_users`](https://github.com/gaato/pyevp/blob/main/examples/fastapi_users/app.py): fastapi-users registration that falls back to the usual verification email
|
|
159
|
+
- [`examples/authx`](https://github.com/gaato/pyevp/blob/main/examples/authx/app.py): passwordless login with AuthX
|
|
160
|
+
- [`examples/django`](https://github.com/gaato/pyevp/blob/main/examples/django/views.py): plain Django with the template tag and `verify_request`
|
|
161
|
+
- [`examples/django_allauth`](https://github.com/gaato/pyevp/blob/main/examples/django_allauth/evp_allauth.py): a django-allauth adapter
|
|
162
|
+
- [`examples/issuer_fastapi`](https://github.com/gaato/pyevp/blob/main/examples/issuer_fastapi/app.py): an issuer for your own domains
|
|
163
|
+
- [`examples/issuer_django`](https://github.com/gaato/pyevp/blob/main/examples/issuer_django/urls.py): the same issuer on Django, with Django's own users
|
|
164
|
+
|
|
165
|
+
## Contributing
|
|
166
|
+
|
|
167
|
+
See [CONTRIBUTING.md](https://github.com/gaato/pyevp/blob/main/CONTRIBUTING.md).
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
[MIT](https://github.com/gaato/pyevp/blob/main/LICENSE)
|
pyevp-0.1.0/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
# PyEVP
|
|
2
|
+
|
|
3
|
+
[](https://docs.pyevp.dev/en/latest/)
|
|
4
|
+
[](https://github.com/gaato/pyevp/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/gaato/pyevp/actions/workflows/drift.yml)
|
|
6
|
+
[](https://github.com/dickhardt/email-verification)
|
|
7
|
+

|
|
8
|
+
[](https://github.com/astral-sh/ty)
|
|
9
|
+
[](https://github.com/gaato/pyevp/blob/main/LICENSE)
|
|
10
|
+
[](https://deepwiki.com/gaato/pyevp)
|
|
11
|
+
|
|
12
|
+
[日本語](https://github.com/gaato/pyevp/blob/main/README.ja.md)
|
|
13
|
+
|
|
14
|
+
Python library for the **Email Verification Protocol** (EVP): verify tokens as a relying party,
|
|
15
|
+
or issue them for your own email domains. With EVP, the browser obtains a token from the user's
|
|
16
|
+
email provider proving they control an address, and your server verifies it, with no confirmation
|
|
17
|
+
email round-trip.
|
|
18
|
+
|
|
19
|
+
**Documentation: <https://docs.pyevp.dev/>**
|
|
20
|
+
|
|
21
|
+
> **Status: alpha.** The protocol ([draft-hardt-email-verification], [WICG Email Verification API])
|
|
22
|
+
> and browser support (Chrome origin trial) are still changing. This library isolates every
|
|
23
|
+
> moving part in a versioned `Profile` so it can follow along.
|
|
24
|
+
|
|
25
|
+
[draft-hardt-email-verification]: https://github.com/dickhardt/email-verification
|
|
26
|
+
[WICG Email Verification API]: https://github.com/WICG/email-verification
|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install "pyevp[dns,httpx2]" # core + the DNS and HTTP adapters
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The core depends only on [joserfc] and idna. DNS and HTTP are pluggable; `[dns,httpx2]` installs
|
|
35
|
+
the default adapters used by `Verifier.default()`. `[all]` installs every optional dependency,
|
|
36
|
+
including the Django integration and the command line.
|
|
37
|
+
|
|
38
|
+
The HTTP adapters work with [httpx2] (pydantic's maintained fork of httpx) or httpx and prefer
|
|
39
|
+
httpx2 when both are installed, so `pip install "pyevp[dns,httpx]"` works too. A client from either
|
|
40
|
+
library can be passed explicitly, e.g. `HttpxFetcher(httpx.Client(...))`.
|
|
41
|
+
|
|
42
|
+
[httpx2]: https://github.com/pydantic/httpx2
|
|
43
|
+
|
|
44
|
+
[joserfc]: https://jose.authlib.org/
|
|
45
|
+
|
|
46
|
+
## How it works
|
|
47
|
+
|
|
48
|
+
1. Render a form with a fresh nonce stored in the user's session:
|
|
49
|
+
|
|
50
|
+
```html
|
|
51
|
+
<input type="email" name="email" autocomplete="email">
|
|
52
|
+
<input type="hidden" name="evt" autocomplete="email-verification-token" nonce="{{ nonce }}">
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
2. When the user picks an address, the browser fills `evt` with `<EVT>~<KB-JWT>`.
|
|
56
|
+
3. On submit, verify it:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from pyevp import Verifier, EVPError, generate_nonce
|
|
60
|
+
|
|
61
|
+
verifier = Verifier.default(audience="https://example.com") # your origin
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
result = verifier.verify(form["evt"], nonce=session.pop("evp_nonce"), email=form["email"])
|
|
65
|
+
except EVPError as exc:
|
|
66
|
+
... # exc.code is an ErrorCode, e.g. "nonce_mismatch"; fall back to email confirmation
|
|
67
|
+
else:
|
|
68
|
+
result.email, result.issuer # verified
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
`AsyncVerifier` has the same API with `await verifier.verify(...)`.
|
|
72
|
+
|
|
73
|
+
Verification checks the key-binding JWT (audience, nonce, freshness, `sd_hash`, holder signature)
|
|
74
|
+
before doing any I/O. It then discovers the issuer from DNS (`_email-verification.<domain>`
|
|
75
|
+
TXT `iss=…`), fetches its metadata and JWKS (cached), and verifies the issuer's signature. Only
|
|
76
|
+
hosts derived from DNS are ever contacted, never hosts named in the token. Before connecting, the
|
|
77
|
+
default fetchers also check that the host resolves only to public addresses; see
|
|
78
|
+
[private networks](https://docs.pyevp.dev/en/latest/guides/transport.html#ssrf) for what this check
|
|
79
|
+
does not catch.
|
|
80
|
+
|
|
81
|
+
Every rejected token raises an `EVPError` with an `ErrorCode`. The safe default is to fall back to your existing
|
|
82
|
+
verification flow; the [error table](https://docs.pyevp.dev/en/latest/quickstart.html#handle-failures) tells which codes
|
|
83
|
+
the user can retry and which point at your configuration.
|
|
84
|
+
|
|
85
|
+
## Command line
|
|
86
|
+
|
|
87
|
+
`pyevp[cli]` installs a `pyevp` command for relying-party developers and operators, and for
|
|
88
|
+
issuer operators checking their own setup. It runs without installing anything into your project:
|
|
89
|
+
|
|
90
|
+
```sh
|
|
91
|
+
uvx --from "pyevp[cli]" pyevp discover gmail.com # DNS record, metadata, keys vs. profile
|
|
92
|
+
pbpaste | uvx --from "pyevp[cli]" pyevp inspect # decode a token offline (no signature checks)
|
|
93
|
+
uvx --from "pyevp[cli]" pyevp verify "$TOKEN" --audience https://example.com --nonce "$NONCE"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
See the [CLI guide](https://docs.pyevp.dev/en/latest/guides/cli.html) for every command and option.
|
|
97
|
+
|
|
98
|
+
## More
|
|
99
|
+
|
|
100
|
+
- [Frameworks](https://docs.pyevp.dev/en/latest/guides/frameworks.html): FastAPI, Flask, fastapi-users, AuthX and Django
|
|
101
|
+
- [Testing your application](https://docs.pyevp.dev/en/latest/guides/testing.html): `FakeIssuer` and `FakeBrowser`, no network needed
|
|
102
|
+
- [Replay protection](https://docs.pyevp.dev/en/latest/guides/replay.html), [logging and metrics](https://docs.pyevp.dev/en/latest/guides/observability.html)
|
|
103
|
+
- [DNS, HTTP and caching](https://docs.pyevp.dev/en/latest/guides/transport.html): DNS over HTTPS, a standard-library-only setup, private networks
|
|
104
|
+
- [Profiles](https://docs.pyevp.dev/en/latest/concepts.html#profiles): how PyEVP follows a protocol that is still changing
|
|
105
|
+
- [Running an issuer](https://docs.pyevp.dev/en/latest/guides/issuer-operations.html) for your own mail domains
|
|
106
|
+
- [Compatibility policy](https://docs.pyevp.dev/en/latest/compatibility.html)
|
|
107
|
+
|
|
108
|
+
## Examples
|
|
109
|
+
|
|
110
|
+
Each example is a standalone project with its own tests:
|
|
111
|
+
|
|
112
|
+
- [`examples/fastapi`](https://github.com/gaato/pyevp/blob/main/examples/fastapi/app.py): FastAPI with session nonces
|
|
113
|
+
- [`examples/flask`](https://github.com/gaato/pyevp/blob/main/examples/flask/app.py): the same flow with the synchronous `Verifier`
|
|
114
|
+
- [`examples/fastapi_spa`](https://github.com/gaato/pyevp/blob/main/examples/fastapi_spa/app.py): a JSON API for a single-page app, without server sessions, with password recovery
|
|
115
|
+
- [`examples/fastapi_users`](https://github.com/gaato/pyevp/blob/main/examples/fastapi_users/app.py): fastapi-users registration that falls back to the usual verification email
|
|
116
|
+
- [`examples/authx`](https://github.com/gaato/pyevp/blob/main/examples/authx/app.py): passwordless login with AuthX
|
|
117
|
+
- [`examples/django`](https://github.com/gaato/pyevp/blob/main/examples/django/views.py): plain Django with the template tag and `verify_request`
|
|
118
|
+
- [`examples/django_allauth`](https://github.com/gaato/pyevp/blob/main/examples/django_allauth/evp_allauth.py): a django-allauth adapter
|
|
119
|
+
- [`examples/issuer_fastapi`](https://github.com/gaato/pyevp/blob/main/examples/issuer_fastapi/app.py): an issuer for your own domains
|
|
120
|
+
- [`examples/issuer_django`](https://github.com/gaato/pyevp/blob/main/examples/issuer_django/urls.py): the same issuer on Django, with Django's own users
|
|
121
|
+
|
|
122
|
+
## Contributing
|
|
123
|
+
|
|
124
|
+
See [CONTRIBUTING.md](https://github.com/gaato/pyevp/blob/main/CONTRIBUTING.md).
|
|
125
|
+
|
|
126
|
+
## License
|
|
127
|
+
|
|
128
|
+
[MIT](https://github.com/gaato/pyevp/blob/main/LICENSE)
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "PyEVP"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python library for the Email Verification Protocol (EVP): verify tokens as a relying party, or issue them for your own email domains"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
requires-python = ">=3.11"
|
|
9
|
+
keywords = [
|
|
10
|
+
"email",
|
|
11
|
+
"verification",
|
|
12
|
+
"evp",
|
|
13
|
+
"sd-jwt",
|
|
14
|
+
"jose",
|
|
15
|
+
"authentication",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Programming Language :: Python :: 3.14",
|
|
26
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
27
|
+
"Topic :: Security",
|
|
28
|
+
"Typing :: Typed",
|
|
29
|
+
]
|
|
30
|
+
dependencies = [
|
|
31
|
+
"idna>=3.7",
|
|
32
|
+
"joserfc>=1.7",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[[project.authors]]
|
|
36
|
+
name = "Gakuto Furuya"
|
|
37
|
+
email = "g.furuya@gaato.net"
|
|
38
|
+
|
|
39
|
+
[project.optional-dependencies]
|
|
40
|
+
dns = ["dnspython>=2.7"]
|
|
41
|
+
httpx = [
|
|
42
|
+
"anyio>=4.5",
|
|
43
|
+
"httpx>=0.28",
|
|
44
|
+
]
|
|
45
|
+
httpx2 = [
|
|
46
|
+
"anyio>=4.5",
|
|
47
|
+
"httpx2>=2.13",
|
|
48
|
+
]
|
|
49
|
+
all = ["pyevp[dns,httpx2,django,cli]"]
|
|
50
|
+
cli = [
|
|
51
|
+
"pyevp[dns,httpx2]",
|
|
52
|
+
"typer>=0.27",
|
|
53
|
+
]
|
|
54
|
+
django = ["django>=4.2"]
|
|
55
|
+
|
|
56
|
+
[project.scripts]
|
|
57
|
+
pyevp = "pyevp.__main__:main"
|
|
58
|
+
|
|
59
|
+
[project.urls]
|
|
60
|
+
Documentation = "https://docs.pyevp.dev/"
|
|
61
|
+
Repository = "https://github.com/gaato/pyevp"
|
|
62
|
+
Changelog = "https://github.com/gaato/pyevp/blob/main/CHANGELOG.md"
|
|
63
|
+
|
|
64
|
+
[build-system]
|
|
65
|
+
requires = ["uv_build>=0.12.21,<0.13.0"]
|
|
66
|
+
build-backend = "uv_build"
|
|
67
|
+
|
|
68
|
+
[dependency-groups]
|
|
69
|
+
dev = [
|
|
70
|
+
"anyio>=4.15.1",
|
|
71
|
+
"django>=6.1.1",
|
|
72
|
+
"httpx2>=2.13",
|
|
73
|
+
"pytest>=9.1.1",
|
|
74
|
+
"ruff>=0.16.9",
|
|
75
|
+
"ty>=0.0.84",
|
|
76
|
+
]
|
|
77
|
+
interop = ["websockets>=17.1"]
|
|
78
|
+
docs = [
|
|
79
|
+
"myst-parser>=5.1",
|
|
80
|
+
"shibuya>=2026.7.12",
|
|
81
|
+
"sphinx>=9.1",
|
|
82
|
+
"sphinx-intl>=2.4",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[tool.pytest.ini_options]
|
|
86
|
+
testpaths = ["tests"]
|
|
87
|
+
addopts = [
|
|
88
|
+
"-ra",
|
|
89
|
+
"--strict-markers",
|
|
90
|
+
"-m",
|
|
91
|
+
"not network",
|
|
92
|
+
]
|
|
93
|
+
markers = ["network: talks to real DNS / HTTPS endpoints (deselected by default)"]
|
|
94
|
+
filterwarnings = ["error"]
|
|
95
|
+
|
|
96
|
+
[tool.ruff]
|
|
97
|
+
line-length = 100
|
|
98
|
+
|
|
99
|
+
[tool.ruff.lint]
|
|
100
|
+
select = [
|
|
101
|
+
"E",
|
|
102
|
+
"F",
|
|
103
|
+
"W",
|
|
104
|
+
"I",
|
|
105
|
+
"UP",
|
|
106
|
+
"B",
|
|
107
|
+
"SIM",
|
|
108
|
+
"RUF",
|
|
109
|
+
"PT",
|
|
110
|
+
"C4",
|
|
111
|
+
"PIE",
|
|
112
|
+
"RET",
|
|
113
|
+
"PL",
|
|
114
|
+
]
|
|
115
|
+
ignore = [
|
|
116
|
+
"PLR0913",
|
|
117
|
+
"PLR2004",
|
|
118
|
+
"PLR0911",
|
|
119
|
+
"PLR0912",
|
|
120
|
+
]
|
|
121
|
+
|
|
122
|
+
[tool.ruff.lint.per-file-ignores]
|
|
123
|
+
"tests/**" = ["PLR"]
|
|
124
|
+
"src/pyevp/cli/**" = [
|
|
125
|
+
"PLR0915",
|
|
126
|
+
"PLR0917",
|
|
127
|
+
]
|
|
128
|
+
"src/pyevp/contrib/django/migrations/**" = ["RUF012"]
|
|
129
|
+
|
|
130
|
+
[tool.uv.workspace]
|
|
131
|
+
members = ["examples/*"]
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "PyEVP"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Python library for the Email Verification Protocol (EVP): verify tokens as a relying party, or issue them for your own email domains"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Gakuto Furuya", email = "g.furuya@gaato.net" }
|
|
8
|
+
]
|
|
9
|
+
license = "MIT"
|
|
10
|
+
license-files = ["LICENSE"]
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
keywords = ["email", "verification", "evp", "sd-jwt", "jose", "authentication"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
23
|
+
"Topic :: Security",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"idna>=3.7",
|
|
28
|
+
"joserfc>=1.7",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dns = [
|
|
33
|
+
"dnspython>=2.7",
|
|
34
|
+
]
|
|
35
|
+
httpx = [
|
|
36
|
+
"anyio>=4.5",
|
|
37
|
+
"httpx>=0.28",
|
|
38
|
+
]
|
|
39
|
+
httpx2 = [
|
|
40
|
+
"anyio>=4.5",
|
|
41
|
+
"httpx2>=2.13",
|
|
42
|
+
]
|
|
43
|
+
all = [
|
|
44
|
+
"pyevp[dns,httpx2,django,cli]",
|
|
45
|
+
]
|
|
46
|
+
cli = [
|
|
47
|
+
"pyevp[dns,httpx2]",
|
|
48
|
+
"typer>=0.27",
|
|
49
|
+
]
|
|
50
|
+
django = [
|
|
51
|
+
"django>=4.2",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[project.scripts]
|
|
55
|
+
pyevp = "pyevp.__main__:main"
|
|
56
|
+
|
|
57
|
+
[project.urls]
|
|
58
|
+
Documentation = "https://docs.pyevp.dev/"
|
|
59
|
+
Repository = "https://github.com/gaato/pyevp"
|
|
60
|
+
Changelog = "https://github.com/gaato/pyevp/blob/main/CHANGELOG.md"
|
|
61
|
+
|
|
62
|
+
[build-system]
|
|
63
|
+
requires = ["uv_build>=0.12.21,<0.13.0"]
|
|
64
|
+
build-backend = "uv_build"
|
|
65
|
+
|
|
66
|
+
[dependency-groups]
|
|
67
|
+
dev = [
|
|
68
|
+
"anyio>=4.15.1",
|
|
69
|
+
"django>=6.1.1",
|
|
70
|
+
"httpx2>=2.13",
|
|
71
|
+
"pytest>=9.1.1",
|
|
72
|
+
"ruff>=0.16.9",
|
|
73
|
+
"ty>=0.0.84",
|
|
74
|
+
]
|
|
75
|
+
# The nightly Chrome interop test (interop/chrome_evp.py).
|
|
76
|
+
interop = [
|
|
77
|
+
"websockets>=17.1",
|
|
78
|
+
]
|
|
79
|
+
docs = [
|
|
80
|
+
"myst-parser>=5.1",
|
|
81
|
+
"shibuya>=2026.7.12",
|
|
82
|
+
"sphinx>=9.1",
|
|
83
|
+
"sphinx-intl>=2.4",
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
[tool.pytest.ini_options]
|
|
87
|
+
testpaths = ["tests"]
|
|
88
|
+
addopts = ["-ra", "--strict-markers", "-m", "not network"]
|
|
89
|
+
markers = [
|
|
90
|
+
"network: talks to real DNS / HTTPS endpoints (deselected by default)",
|
|
91
|
+
]
|
|
92
|
+
filterwarnings = ["error"]
|
|
93
|
+
|
|
94
|
+
[tool.ruff]
|
|
95
|
+
line-length = 100
|
|
96
|
+
|
|
97
|
+
[tool.ruff.lint]
|
|
98
|
+
select = ["E", "F", "W", "I", "UP", "B", "SIM", "RUF", "PT", "C4", "PIE", "RET", "PL"]
|
|
99
|
+
ignore = ["PLR0913", "PLR2004", "PLR0911", "PLR0912"]
|
|
100
|
+
|
|
101
|
+
[tool.ruff.lint.per-file-ignores]
|
|
102
|
+
"tests/**" = ["PLR"]
|
|
103
|
+
# Typer maps CLI options to parameters; commands are closures inside make_app().
|
|
104
|
+
"src/pyevp/cli/**" = ["PLR0915", "PLR0917"]
|
|
105
|
+
# Django's generated migration style.
|
|
106
|
+
"src/pyevp/contrib/django/migrations/**" = ["RUF012"]
|
|
107
|
+
|
|
108
|
+
[tool.uv.workspace]
|
|
109
|
+
members = ["examples/*"]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Relying-party verification for the Email Verification Protocol (EVP)."""
|
|
2
|
+
|
|
3
|
+
from pyevp._email import emails_match
|
|
4
|
+
from pyevp.cache import AsyncCache, Cache, CacheEntry, InMemoryCache, NullCache
|
|
5
|
+
from pyevp.errors import DiscoveryError, ErrorCode, EVPError, PolicyError, TokenError
|
|
6
|
+
from pyevp.nonce import generate_nonce, nonces_equal
|
|
7
|
+
from pyevp.observability import LoggingObserver, Observer, VerificationEvent
|
|
8
|
+
from pyevp.ports import AsyncJsonFetcher, AsyncTxtResolver, Clock, JsonFetcher, TxtResolver
|
|
9
|
+
from pyevp.profile import DEFAULT_PROFILE, EmailComparison, IssuerFormat, Profile
|
|
10
|
+
from pyevp.replay import AsyncReplayGuard, InMemoryReplayGuard, ReplayGuard
|
|
11
|
+
from pyevp.types import IssuerMetadata, VerifiedEmail
|
|
12
|
+
from pyevp.verifier import AsyncVerifier, Verifier
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"DEFAULT_PROFILE",
|
|
16
|
+
"AsyncCache",
|
|
17
|
+
"AsyncJsonFetcher",
|
|
18
|
+
"AsyncReplayGuard",
|
|
19
|
+
"AsyncTxtResolver",
|
|
20
|
+
"AsyncVerifier",
|
|
21
|
+
"Cache",
|
|
22
|
+
"CacheEntry",
|
|
23
|
+
"Clock",
|
|
24
|
+
"DiscoveryError",
|
|
25
|
+
"EVPError",
|
|
26
|
+
"EmailComparison",
|
|
27
|
+
"ErrorCode",
|
|
28
|
+
"InMemoryCache",
|
|
29
|
+
"InMemoryReplayGuard",
|
|
30
|
+
"IssuerFormat",
|
|
31
|
+
"IssuerMetadata",
|
|
32
|
+
"JsonFetcher",
|
|
33
|
+
"LoggingObserver",
|
|
34
|
+
"NullCache",
|
|
35
|
+
"Observer",
|
|
36
|
+
"PolicyError",
|
|
37
|
+
"Profile",
|
|
38
|
+
"ReplayGuard",
|
|
39
|
+
"TokenError",
|
|
40
|
+
"TxtResolver",
|
|
41
|
+
"VerificationEvent",
|
|
42
|
+
"VerifiedEmail",
|
|
43
|
+
"Verifier",
|
|
44
|
+
"emails_match",
|
|
45
|
+
"generate_nonce",
|
|
46
|
+
"nonces_equal",
|
|
47
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""``pyevp`` command / ``python -m pyevp``. Requires ``pip install "pyevp[cli]"``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
|
|
7
|
+
MISSING_EXTRA = 3
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main() -> None:
|
|
11
|
+
try:
|
|
12
|
+
from pyevp.cli import app # noqa: PLC0415
|
|
13
|
+
except ImportError as exc:
|
|
14
|
+
if exc.name not in {"typer", "click", "rich"}:
|
|
15
|
+
raise
|
|
16
|
+
print(
|
|
17
|
+
'The pyevp command needs the "cli" extra:\n'
|
|
18
|
+
' pip install "pyevp[cli]"\n'
|
|
19
|
+
"or run it without installing:\n"
|
|
20
|
+
' uvx --from "pyevp[cli]" pyevp --help',
|
|
21
|
+
file=sys.stderr,
|
|
22
|
+
)
|
|
23
|
+
raise SystemExit(MISSING_EXTRA) from None
|
|
24
|
+
app()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __name__ == "__main__":
|
|
28
|
+
main()
|