sanic-security 1.16.7__tar.gz → 1.16.9__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.
- {sanic_security-1.16.7/sanic_security.egg-info → sanic_security-1.16.9}/PKG-INFO +17 -27
- {sanic_security-1.16.7 → sanic_security-1.16.9}/README.md +15 -26
- {sanic_security-1.16.7 → sanic_security-1.16.9}/pyproject.toml +1 -1
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/authorization.py +1 -1
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/configuration.py +10 -16
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/oauth.py +3 -1
- {sanic_security-1.16.7 → sanic_security-1.16.9/sanic_security.egg-info}/PKG-INFO +17 -27
- {sanic_security-1.16.7 → sanic_security-1.16.9}/LICENSE +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/__init__.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/authentication.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/exceptions.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/models.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/test/__init__.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/test/server.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/test/tests.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/utils.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security/verification.py +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security.egg-info/SOURCES.txt +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security.egg-info/dependency_links.txt +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security.egg-info/requires.txt +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security.egg-info/top_level.txt +0 -0
- {sanic_security-1.16.7 → sanic_security-1.16.9}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: sanic-security
|
3
|
-
Version: 1.16.
|
3
|
+
Version: 1.16.9
|
4
4
|
Summary: An async security library for the Sanic framework.
|
5
5
|
Author-email: Aidan Stewart <me@na-stewart.com>
|
6
6
|
Project-URL: Documentation, https://security.na-stewart.com/
|
@@ -29,15 +29,7 @@ Requires-Dist: pdoc3; extra == "dev"
|
|
29
29
|
Requires-Dist: cryptography; extra == "dev"
|
30
30
|
Provides-Extra: crypto
|
31
31
|
Requires-Dist: cryptography>=3.3.1; extra == "crypto"
|
32
|
-
|
33
|
-
<!-- PROJECT SHIELDS -->
|
34
|
-
<!--
|
35
|
-
*** I'm using markdown "reference style" links for readability.
|
36
|
-
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
37
|
-
*** See the bottom of this document for the declaration of the reference variables
|
38
|
-
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
39
|
-
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
40
|
-
-->
|
32
|
+
Dynamic: license-file
|
41
33
|
|
42
34
|
[](https://github.com/psf/black)
|
43
35
|
[](https://pepy.tech/project/sanic-security)
|
@@ -79,7 +71,7 @@ Requires-Dist: cryptography>=3.3.1; extra == "crypto"
|
|
79
71
|
## About The Project
|
80
72
|
|
81
73
|
Sanic Security is an authentication, authorization, and verification library designed for use with the
|
82
|
-
[Sanic](https://github.com/huge-success/sanic) framework.
|
74
|
+
[Sanic](https://github.com/huge-success/sanic) web app framework.
|
83
75
|
|
84
76
|
* OAuth2 integration
|
85
77
|
* Login, registration, and authentication with refresh mechanisms
|
@@ -94,16 +86,16 @@ Visit [security.na-stewart.com](https://security.na-stewart.com) for documentati
|
|
94
86
|
<!-- GETTING STARTED -->
|
95
87
|
## Getting Started
|
96
88
|
|
97
|
-
In order to get started, please install [PyPI](https://pypi.org/).
|
89
|
+
In order to get started, please install [PyPI](https://pypi.org/) (likely included with your Python build).
|
98
90
|
|
99
91
|
### Installation
|
100
92
|
|
101
|
-
* Install the Sanic Security
|
93
|
+
* Install the Sanic Security package.
|
102
94
|
```shell
|
103
95
|
pip3 install sanic-security
|
104
96
|
````
|
105
97
|
|
106
|
-
* Install the Sanic Security
|
98
|
+
* Install the Sanic Security package with the [cryptography](https://github.com/pyca/cryptography) dependency included.
|
107
99
|
|
108
100
|
If you're planning on encoding or decoding JWTs using certain digital signature algorithms (like RSA or ECDSA which use
|
109
101
|
the public secret and private secret), you will need to install the `cryptography` library. This can be installed explicitly, or
|
@@ -113,7 +105,7 @@ as an extra requirement.
|
|
113
105
|
pip3 install sanic-security[crypto]
|
114
106
|
````
|
115
107
|
|
116
|
-
* Install the Sanic Security
|
108
|
+
* Install the Sanic Security package with the [httpx-oauth](https://github.com/frankie567/httpx-oauth) dependency included.
|
117
109
|
|
118
110
|
If you're planning on utilizing OAuth, you will need to install the `httpx-oauth` library. This can be installed explicitly, or
|
119
111
|
as an extra requirement.
|
@@ -130,8 +122,7 @@ pip3 install sanic-security --upgrade
|
|
130
122
|
|
131
123
|
### Configuration
|
132
124
|
|
133
|
-
Sanic Security configuration is merely an object that can be modified either using dot-notation or like a
|
134
|
-
dictionary.
|
125
|
+
Sanic Security configuration is merely an object that can be modified either using dot-notation or like a dictionary.
|
135
126
|
|
136
127
|
For example:
|
137
128
|
|
@@ -139,7 +130,7 @@ For example:
|
|
139
130
|
from sanic_security.configuration import config as security_config
|
140
131
|
|
141
132
|
security_config.SECRET = "This is a big secret. Shhhhh"
|
142
|
-
security_config["CAPTCHA_FONT"] = "
|
133
|
+
security_config["CAPTCHA_FONT"] = "resources/captcha-font.ttf"
|
143
134
|
```
|
144
135
|
|
145
136
|
You can also use the update() method like on regular dictionaries.
|
@@ -176,8 +167,7 @@ You can load environment variables with a different prefix via `security_config.
|
|
176
167
|
|
177
168
|
## Usage
|
178
169
|
|
179
|
-
Sanic Security's authentication and verification functionality is session based. A new session will be created for the user after the user logs in or requests some form of verification (two-step, captcha). The session data is then encoded into a JWT and stored on a cookie on the user’s browser. The session cookie is then sent
|
180
|
-
along with every subsequent request. The server can then compare the session stored on the cookie against the session information stored in the database to verify user’s identity and send a response with the corresponding state.
|
170
|
+
Sanic Security's authentication and verification functionality is session based. A new session will be created for the user after the user logs in or requests some form of verification (two-step, captcha). The session data is then encoded into a JWT and stored on a cookie on the user’s browser. The session cookie is then sent along with every subsequent request. The server can then compare the session stored on the cookie against the session information stored in the database to verify user’s identity and send a response with the corresponding state.
|
181
171
|
|
182
172
|
* Initialize Sanic Security as follows:
|
183
173
|
```python
|
@@ -267,7 +257,7 @@ async def on_oauth_token(request):
|
|
267
257
|
|
268
258
|
## Authentication
|
269
259
|
|
270
|
-
* Registration (
|
260
|
+
* Registration (with two-step account verification)
|
271
261
|
|
272
262
|
Phone can be null or empty.
|
273
263
|
|
@@ -310,7 +300,7 @@ async def on_verify(request):
|
|
310
300
|
)
|
311
301
|
```
|
312
302
|
|
313
|
-
* Login (
|
303
|
+
* Login (with two-factor authentication)
|
314
304
|
|
315
305
|
Credentials are retrieved via header are constructed by first combining the username and the password with a colon
|
316
306
|
(aladdin:opensesame), and then by encoding the resulting string in base64 (YWxhZGRpbjpvcGVuc2VzYW1l).
|
@@ -399,7 +389,7 @@ async def on_authenticate(request):
|
|
399
389
|
return response
|
400
390
|
```
|
401
391
|
|
402
|
-
* Requires Authentication (
|
392
|
+
* Requires Authentication (this method is not called directly and instead used as a decorator)
|
403
393
|
|
404
394
|
```python
|
405
395
|
@app.post("api/security/auth")
|
@@ -450,7 +440,7 @@ async def on_captcha(request):
|
|
450
440
|
return json("Captcha attempt successful!", captcha_session.json)
|
451
441
|
```
|
452
442
|
|
453
|
-
* Requires CAPTCHA (
|
443
|
+
* Requires CAPTCHA (this method is not called directly and instead used as a decorator)
|
454
444
|
|
455
445
|
| Key | Value |
|
456
446
|
|-------------|--------|
|
@@ -511,7 +501,7 @@ async def on_two_step_verification(request):
|
|
511
501
|
return response
|
512
502
|
```
|
513
503
|
|
514
|
-
* Requires Two-step Verification (
|
504
|
+
* Requires Two-step Verification (this method is not called directly and instead used as a decorator)
|
515
505
|
|
516
506
|
| Key | Value |
|
517
507
|
|----------|--------|
|
@@ -564,7 +554,7 @@ async def on_check_perms(request):
|
|
564
554
|
return json("Account is authorized.", authentication_session.json)
|
565
555
|
```
|
566
556
|
|
567
|
-
* Require Permissions (
|
557
|
+
* Require Permissions (this method is not called directly and instead used as a decorator.)
|
568
558
|
|
569
559
|
```python
|
570
560
|
@app.post("api/security/perms")
|
@@ -1,12 +1,3 @@
|
|
1
|
-
<!-- PROJECT SHIELDS -->
|
2
|
-
<!--
|
3
|
-
*** I'm using markdown "reference style" links for readability.
|
4
|
-
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
5
|
-
*** See the bottom of this document for the declaration of the reference variables
|
6
|
-
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
7
|
-
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
8
|
-
-->
|
9
|
-
|
10
1
|
[](https://github.com/psf/black)
|
11
2
|
[](https://pepy.tech/project/sanic-security)
|
12
3
|
[](https://anaconda.org/conda-forge/sanic-security)
|
@@ -47,7 +38,7 @@
|
|
47
38
|
## About The Project
|
48
39
|
|
49
40
|
Sanic Security is an authentication, authorization, and verification library designed for use with the
|
50
|
-
[Sanic](https://github.com/huge-success/sanic) framework.
|
41
|
+
[Sanic](https://github.com/huge-success/sanic) web app framework.
|
51
42
|
|
52
43
|
* OAuth2 integration
|
53
44
|
* Login, registration, and authentication with refresh mechanisms
|
@@ -62,16 +53,16 @@ Visit [security.na-stewart.com](https://security.na-stewart.com) for documentati
|
|
62
53
|
<!-- GETTING STARTED -->
|
63
54
|
## Getting Started
|
64
55
|
|
65
|
-
In order to get started, please install [PyPI](https://pypi.org/).
|
56
|
+
In order to get started, please install [PyPI](https://pypi.org/) (likely included with your Python build).
|
66
57
|
|
67
58
|
### Installation
|
68
59
|
|
69
|
-
* Install the Sanic Security
|
60
|
+
* Install the Sanic Security package.
|
70
61
|
```shell
|
71
62
|
pip3 install sanic-security
|
72
63
|
````
|
73
64
|
|
74
|
-
* Install the Sanic Security
|
65
|
+
* Install the Sanic Security package with the [cryptography](https://github.com/pyca/cryptography) dependency included.
|
75
66
|
|
76
67
|
If you're planning on encoding or decoding JWTs using certain digital signature algorithms (like RSA or ECDSA which use
|
77
68
|
the public secret and private secret), you will need to install the `cryptography` library. This can be installed explicitly, or
|
@@ -81,7 +72,7 @@ as an extra requirement.
|
|
81
72
|
pip3 install sanic-security[crypto]
|
82
73
|
````
|
83
74
|
|
84
|
-
* Install the Sanic Security
|
75
|
+
* Install the Sanic Security package with the [httpx-oauth](https://github.com/frankie567/httpx-oauth) dependency included.
|
85
76
|
|
86
77
|
If you're planning on utilizing OAuth, you will need to install the `httpx-oauth` library. This can be installed explicitly, or
|
87
78
|
as an extra requirement.
|
@@ -98,8 +89,7 @@ pip3 install sanic-security --upgrade
|
|
98
89
|
|
99
90
|
### Configuration
|
100
91
|
|
101
|
-
Sanic Security configuration is merely an object that can be modified either using dot-notation or like a
|
102
|
-
dictionary.
|
92
|
+
Sanic Security configuration is merely an object that can be modified either using dot-notation or like a dictionary.
|
103
93
|
|
104
94
|
For example:
|
105
95
|
|
@@ -107,7 +97,7 @@ For example:
|
|
107
97
|
from sanic_security.configuration import config as security_config
|
108
98
|
|
109
99
|
security_config.SECRET = "This is a big secret. Shhhhh"
|
110
|
-
security_config["CAPTCHA_FONT"] = "
|
100
|
+
security_config["CAPTCHA_FONT"] = "resources/captcha-font.ttf"
|
111
101
|
```
|
112
102
|
|
113
103
|
You can also use the update() method like on regular dictionaries.
|
@@ -144,8 +134,7 @@ You can load environment variables with a different prefix via `security_config.
|
|
144
134
|
|
145
135
|
## Usage
|
146
136
|
|
147
|
-
Sanic Security's authentication and verification functionality is session based. A new session will be created for the user after the user logs in or requests some form of verification (two-step, captcha). The session data is then encoded into a JWT and stored on a cookie on the user’s browser. The session cookie is then sent
|
148
|
-
along with every subsequent request. The server can then compare the session stored on the cookie against the session information stored in the database to verify user’s identity and send a response with the corresponding state.
|
137
|
+
Sanic Security's authentication and verification functionality is session based. A new session will be created for the user after the user logs in or requests some form of verification (two-step, captcha). The session data is then encoded into a JWT and stored on a cookie on the user’s browser. The session cookie is then sent along with every subsequent request. The server can then compare the session stored on the cookie against the session information stored in the database to verify user’s identity and send a response with the corresponding state.
|
149
138
|
|
150
139
|
* Initialize Sanic Security as follows:
|
151
140
|
```python
|
@@ -235,7 +224,7 @@ async def on_oauth_token(request):
|
|
235
224
|
|
236
225
|
## Authentication
|
237
226
|
|
238
|
-
* Registration (
|
227
|
+
* Registration (with two-step account verification)
|
239
228
|
|
240
229
|
Phone can be null or empty.
|
241
230
|
|
@@ -278,7 +267,7 @@ async def on_verify(request):
|
|
278
267
|
)
|
279
268
|
```
|
280
269
|
|
281
|
-
* Login (
|
270
|
+
* Login (with two-factor authentication)
|
282
271
|
|
283
272
|
Credentials are retrieved via header are constructed by first combining the username and the password with a colon
|
284
273
|
(aladdin:opensesame), and then by encoding the resulting string in base64 (YWxhZGRpbjpvcGVuc2VzYW1l).
|
@@ -367,7 +356,7 @@ async def on_authenticate(request):
|
|
367
356
|
return response
|
368
357
|
```
|
369
358
|
|
370
|
-
* Requires Authentication (
|
359
|
+
* Requires Authentication (this method is not called directly and instead used as a decorator)
|
371
360
|
|
372
361
|
```python
|
373
362
|
@app.post("api/security/auth")
|
@@ -418,7 +407,7 @@ async def on_captcha(request):
|
|
418
407
|
return json("Captcha attempt successful!", captcha_session.json)
|
419
408
|
```
|
420
409
|
|
421
|
-
* Requires CAPTCHA (
|
410
|
+
* Requires CAPTCHA (this method is not called directly and instead used as a decorator)
|
422
411
|
|
423
412
|
| Key | Value |
|
424
413
|
|-------------|--------|
|
@@ -479,7 +468,7 @@ async def on_two_step_verification(request):
|
|
479
468
|
return response
|
480
469
|
```
|
481
470
|
|
482
|
-
* Requires Two-step Verification (
|
471
|
+
* Requires Two-step Verification (this method is not called directly and instead used as a decorator)
|
483
472
|
|
484
473
|
| Key | Value |
|
485
474
|
|----------|--------|
|
@@ -532,7 +521,7 @@ async def on_check_perms(request):
|
|
532
521
|
return json("Account is authorized.", authentication_session.json)
|
533
522
|
```
|
534
523
|
|
535
|
-
* Require Permissions (
|
524
|
+
* Require Permissions (this method is not called directly and instead used as a decorator.)
|
536
525
|
|
537
526
|
```python
|
538
527
|
@app.post("api/security/perms")
|
@@ -650,4 +639,4 @@ Distributed under the MIT License. See `LICENSE` for more information.
|
|
650
639
|
|
651
640
|
* PATCH version when you make backwards compatible bug fixes.
|
652
641
|
|
653
|
-
[https://semver.org/](https://semver.org/)
|
642
|
+
[https://semver.org/](https://semver.org/)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from os import environ
|
2
|
+
from types import SimpleNamespace
|
2
3
|
|
3
4
|
from sanic.utils import str_to_bool
|
4
5
|
|
@@ -50,7 +51,7 @@ DEFAULT_CONFIG = {
|
|
50
51
|
}
|
51
52
|
|
52
53
|
|
53
|
-
class Config(
|
54
|
+
class Config(SimpleNamespace):
|
54
55
|
"""
|
55
56
|
Sanic Security configuration.
|
56
57
|
|
@@ -102,30 +103,23 @@ class Config(dict):
|
|
102
103
|
INITIAL_ADMIN_PASSWORD: str
|
103
104
|
TEST_DATABASE_URL: str
|
104
105
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
106
|
+
def __init__(self, default_config: dict = None):
|
107
|
+
super().__init__(**(default_config or DEFAULT_CONFIG))
|
108
|
+
self.load_environment_variables()
|
108
109
|
|
109
|
-
|
110
|
-
load_env (str): Prefix being used to apply environment variables into the config.
|
111
|
-
"""
|
110
|
+
def load_environment_variables(self, env_prefix: str = "SANIC_SECURITY_"):
|
112
111
|
for key, value in environ.items():
|
113
|
-
if not key.startswith(
|
112
|
+
if not key.startswith(env_prefix):
|
114
113
|
continue
|
115
114
|
|
116
|
-
_, config_key = key.split(
|
115
|
+
_, config_key = key.split(env_prefix, 1)
|
117
116
|
|
118
117
|
for converter in (int, float, str_to_bool, str):
|
119
118
|
try:
|
120
|
-
self
|
119
|
+
setattr(self, config_key, converter(value))
|
121
120
|
break
|
122
121
|
except ValueError:
|
123
122
|
pass
|
124
123
|
|
125
|
-
def __init__(self):
|
126
|
-
super().__init__(DEFAULT_CONFIG)
|
127
|
-
self.__dict__ = self
|
128
|
-
self.load_environment_variables()
|
129
|
-
|
130
124
|
|
131
|
-
config = Config()
|
125
|
+
config = Config(DEFAULT_CONFIG)
|
@@ -149,7 +149,9 @@ async def oauth_revoke(request: Request, client: BaseOAuth2) -> dict:
|
|
149
149
|
token_info = await oauth_decode(request, client, False)
|
150
150
|
request.ctx.oauth["revoked"] = True
|
151
151
|
with suppress(RevokeTokenNotSupportedError):
|
152
|
-
await client.revoke_token(
|
152
|
+
await client.revoke_token(
|
153
|
+
token_info.get("access_token"), "access_token"
|
154
|
+
)
|
153
155
|
return token_info
|
154
156
|
except RevokeTokenError as e:
|
155
157
|
raise OAuthError(f"Failed to revoke access token {e.response.text}")
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.4
|
2
2
|
Name: sanic-security
|
3
|
-
Version: 1.16.
|
3
|
+
Version: 1.16.9
|
4
4
|
Summary: An async security library for the Sanic framework.
|
5
5
|
Author-email: Aidan Stewart <me@na-stewart.com>
|
6
6
|
Project-URL: Documentation, https://security.na-stewart.com/
|
@@ -29,15 +29,7 @@ Requires-Dist: pdoc3; extra == "dev"
|
|
29
29
|
Requires-Dist: cryptography; extra == "dev"
|
30
30
|
Provides-Extra: crypto
|
31
31
|
Requires-Dist: cryptography>=3.3.1; extra == "crypto"
|
32
|
-
|
33
|
-
<!-- PROJECT SHIELDS -->
|
34
|
-
<!--
|
35
|
-
*** I'm using markdown "reference style" links for readability.
|
36
|
-
*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).
|
37
|
-
*** See the bottom of this document for the declaration of the reference variables
|
38
|
-
*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.
|
39
|
-
*** https://www.markdownguide.org/basic-syntax/#reference-style-links
|
40
|
-
-->
|
32
|
+
Dynamic: license-file
|
41
33
|
|
42
34
|
[](https://github.com/psf/black)
|
43
35
|
[](https://pepy.tech/project/sanic-security)
|
@@ -79,7 +71,7 @@ Requires-Dist: cryptography>=3.3.1; extra == "crypto"
|
|
79
71
|
## About The Project
|
80
72
|
|
81
73
|
Sanic Security is an authentication, authorization, and verification library designed for use with the
|
82
|
-
[Sanic](https://github.com/huge-success/sanic) framework.
|
74
|
+
[Sanic](https://github.com/huge-success/sanic) web app framework.
|
83
75
|
|
84
76
|
* OAuth2 integration
|
85
77
|
* Login, registration, and authentication with refresh mechanisms
|
@@ -94,16 +86,16 @@ Visit [security.na-stewart.com](https://security.na-stewart.com) for documentati
|
|
94
86
|
<!-- GETTING STARTED -->
|
95
87
|
## Getting Started
|
96
88
|
|
97
|
-
In order to get started, please install [PyPI](https://pypi.org/).
|
89
|
+
In order to get started, please install [PyPI](https://pypi.org/) (likely included with your Python build).
|
98
90
|
|
99
91
|
### Installation
|
100
92
|
|
101
|
-
* Install the Sanic Security
|
93
|
+
* Install the Sanic Security package.
|
102
94
|
```shell
|
103
95
|
pip3 install sanic-security
|
104
96
|
````
|
105
97
|
|
106
|
-
* Install the Sanic Security
|
98
|
+
* Install the Sanic Security package with the [cryptography](https://github.com/pyca/cryptography) dependency included.
|
107
99
|
|
108
100
|
If you're planning on encoding or decoding JWTs using certain digital signature algorithms (like RSA or ECDSA which use
|
109
101
|
the public secret and private secret), you will need to install the `cryptography` library. This can be installed explicitly, or
|
@@ -113,7 +105,7 @@ as an extra requirement.
|
|
113
105
|
pip3 install sanic-security[crypto]
|
114
106
|
````
|
115
107
|
|
116
|
-
* Install the Sanic Security
|
108
|
+
* Install the Sanic Security package with the [httpx-oauth](https://github.com/frankie567/httpx-oauth) dependency included.
|
117
109
|
|
118
110
|
If you're planning on utilizing OAuth, you will need to install the `httpx-oauth` library. This can be installed explicitly, or
|
119
111
|
as an extra requirement.
|
@@ -130,8 +122,7 @@ pip3 install sanic-security --upgrade
|
|
130
122
|
|
131
123
|
### Configuration
|
132
124
|
|
133
|
-
Sanic Security configuration is merely an object that can be modified either using dot-notation or like a
|
134
|
-
dictionary.
|
125
|
+
Sanic Security configuration is merely an object that can be modified either using dot-notation or like a dictionary.
|
135
126
|
|
136
127
|
For example:
|
137
128
|
|
@@ -139,7 +130,7 @@ For example:
|
|
139
130
|
from sanic_security.configuration import config as security_config
|
140
131
|
|
141
132
|
security_config.SECRET = "This is a big secret. Shhhhh"
|
142
|
-
security_config["CAPTCHA_FONT"] = "
|
133
|
+
security_config["CAPTCHA_FONT"] = "resources/captcha-font.ttf"
|
143
134
|
```
|
144
135
|
|
145
136
|
You can also use the update() method like on regular dictionaries.
|
@@ -176,8 +167,7 @@ You can load environment variables with a different prefix via `security_config.
|
|
176
167
|
|
177
168
|
## Usage
|
178
169
|
|
179
|
-
Sanic Security's authentication and verification functionality is session based. A new session will be created for the user after the user logs in or requests some form of verification (two-step, captcha). The session data is then encoded into a JWT and stored on a cookie on the user’s browser. The session cookie is then sent
|
180
|
-
along with every subsequent request. The server can then compare the session stored on the cookie against the session information stored in the database to verify user’s identity and send a response with the corresponding state.
|
170
|
+
Sanic Security's authentication and verification functionality is session based. A new session will be created for the user after the user logs in or requests some form of verification (two-step, captcha). The session data is then encoded into a JWT and stored on a cookie on the user’s browser. The session cookie is then sent along with every subsequent request. The server can then compare the session stored on the cookie against the session information stored in the database to verify user’s identity and send a response with the corresponding state.
|
181
171
|
|
182
172
|
* Initialize Sanic Security as follows:
|
183
173
|
```python
|
@@ -267,7 +257,7 @@ async def on_oauth_token(request):
|
|
267
257
|
|
268
258
|
## Authentication
|
269
259
|
|
270
|
-
* Registration (
|
260
|
+
* Registration (with two-step account verification)
|
271
261
|
|
272
262
|
Phone can be null or empty.
|
273
263
|
|
@@ -310,7 +300,7 @@ async def on_verify(request):
|
|
310
300
|
)
|
311
301
|
```
|
312
302
|
|
313
|
-
* Login (
|
303
|
+
* Login (with two-factor authentication)
|
314
304
|
|
315
305
|
Credentials are retrieved via header are constructed by first combining the username and the password with a colon
|
316
306
|
(aladdin:opensesame), and then by encoding the resulting string in base64 (YWxhZGRpbjpvcGVuc2VzYW1l).
|
@@ -399,7 +389,7 @@ async def on_authenticate(request):
|
|
399
389
|
return response
|
400
390
|
```
|
401
391
|
|
402
|
-
* Requires Authentication (
|
392
|
+
* Requires Authentication (this method is not called directly and instead used as a decorator)
|
403
393
|
|
404
394
|
```python
|
405
395
|
@app.post("api/security/auth")
|
@@ -450,7 +440,7 @@ async def on_captcha(request):
|
|
450
440
|
return json("Captcha attempt successful!", captcha_session.json)
|
451
441
|
```
|
452
442
|
|
453
|
-
* Requires CAPTCHA (
|
443
|
+
* Requires CAPTCHA (this method is not called directly and instead used as a decorator)
|
454
444
|
|
455
445
|
| Key | Value |
|
456
446
|
|-------------|--------|
|
@@ -511,7 +501,7 @@ async def on_two_step_verification(request):
|
|
511
501
|
return response
|
512
502
|
```
|
513
503
|
|
514
|
-
* Requires Two-step Verification (
|
504
|
+
* Requires Two-step Verification (this method is not called directly and instead used as a decorator)
|
515
505
|
|
516
506
|
| Key | Value |
|
517
507
|
|----------|--------|
|
@@ -564,7 +554,7 @@ async def on_check_perms(request):
|
|
564
554
|
return json("Account is authorized.", authentication_session.json)
|
565
555
|
```
|
566
556
|
|
567
|
-
* Require Permissions (
|
557
|
+
* Require Permissions (this method is not called directly and instead used as a decorator.)
|
568
558
|
|
569
559
|
```python
|
570
560
|
@app.post("api/security/perms")
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{sanic_security-1.16.7 → sanic_security-1.16.9}/sanic_security.egg-info/dependency_links.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|