Skip to content

Commit

Permalink
Docs revision
Browse files Browse the repository at this point in the history
  • Loading branch information
na-stewart committed Jun 24, 2024
1 parent 8841f09 commit 48105f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@
## About The Project

Sanic Security is an authentication, authorization, and verification library designed for use with [Sanic](https://github.com/huge-success/sanic).
This library contains a variety of features including:

* Login, registration, and authentication with refresh mechanisms
* Two-factor authentication
* Captcha
* Two-step verification
* Role based authorization with wildcard permissions

Please visit [security.na-stewart.com](https://security.na-stewart.com) for documentation and [click here for a comprehensive implementation guide](https://blog.na-stewart.com/entry?id=3).
Please visit [security.na-stewart.com](https://security.na-stewart.com) for documentation and [here for an implementation guide](https://blog.na-stewart.com/entry?id=3).

<!-- GETTING STARTED -->
## Getting Started
Expand Down Expand Up @@ -150,7 +149,7 @@ This account can be logged into and has complete authoritative access. Login cre
app.run(host="127.0.0.1", port=8000)
```
* Registration (With Two-step Verification)
* Registration (With two-step account verification)
Phone can be null or empty.
Expand Down Expand Up @@ -192,7 +191,7 @@ async def on_verify(request):
return json("You have verified your account and may login!", two_step_session.json)
```
* Login (With Two-factor Authentication)
* Login (With two-factor authentication)
Login credentials are retrieved via the Authorization header. Credentials are constructed by first combining the
username and the password with a colon (aladdin:opensesame), and then by encoding the resulting string in base64
Expand Down Expand Up @@ -280,7 +279,7 @@ async def on_authenticate(request):
return response
```
* Requires Authentication (This method is not called directly and instead used as a decorator.)
* Requires Authentication (This method is not called directly and instead used as a decorator)
New/Refreshed session will be returned if expired, requires encoding.
Expand All @@ -305,9 +304,12 @@ If it's inconvenient to encode the refreshed session during authentication, it c
```python
@app.on_response
async def authentication_refresh_encoder(request, response):
authentication_session = request.ctx.authentication_session
if authentication_session and authentication_session.is_refresh:
authentication_session.encode(response)
try:
authentication_session = request.ctx.authentication_session
if authentication_session.is_refresh:
authentication_session.encode(response)
except AttributeError:
pass
```
## Captcha
Expand Down Expand Up @@ -343,7 +345,7 @@ async def on_captcha(request):
return json("Captcha attempt successful!", captcha_session.json)
```
* Requires Captcha (This method is not called directly and instead used as a decorator.)
* Requires Captcha (This method is not called directly and instead used as a decorator)
| Key | Value |
|-------------|--------|
Expand Down Expand Up @@ -404,7 +406,7 @@ async def on_two_step_verification(request):
return response
```
* Requires Two-step Verification (This method is not called directly and instead used as a decorator.)
* Requires Two-step Verification (This method is not called directly and instead used as a decorator)
| Key | Value |
|----------|--------|
Expand Down Expand Up @@ -473,7 +475,7 @@ async def on_check_roles(request):
return text("Account is authorized.")
```
* Require Roles (This method is not called directly and instead used as a decorator.)
* Require Roles (This method is not called directly and instead used as a decorator)
```python
@app.post("api/security/roles")
Expand Down
9 changes: 6 additions & 3 deletions sanic_security/test/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,12 @@ async def on_authenticate(request):

@app.on_response
async def authentication_refresh_encoder(request, response):
authentication_session = request.ctx.authentication_session
if authentication_session and authentication_session.is_refresh:
authentication_session.encode(response)
try:
authentication_session = request.ctx.authentication_session
if authentication_session.is_refresh:
authentication_session.encode(response)
except AttributeError:
pass


@app.post("api/test/auth/expire")
Expand Down

0 comments on commit 48105f4

Please sign in to comment.