Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page and Path overloads #50

Merged
merged 2 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 73 additions & 2 deletions docs/client_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def startup():
token_server='0.0.0.0',
token_server_port=8090,
auth_secret='abcd1234',
default_permissoins={'groups': ['users']}
default_permissions={'groups': ['users']}
)

# grants access to users matching default_permissions
Expand Down Expand Up @@ -71,7 +71,7 @@ async def startup():
token_server='0.0.0.0',
token_server_port=8090,
auth_secret='abcd1234',
default_permissoins={'groups': ['users']}
default_permissions={'groups': ['users']}
)

# import sub modules
Expand Down Expand Up @@ -139,3 +139,74 @@ EasyAuth client endpoints, decorated by the auth router, that serve HTML respons
Once logged in, the browser will contain a authenticatin cookie that matches the users token

![](images/cookie.png)


### Page Overloads
It is possible to overload the existing login, register, activation, not_found, and forbidden pages using the page specific "overloader". Just like routers, this should be done after an EasyAuthClient is created.

!!! Danger
Consider reviewing what API's are used / required before overloading any existing page. Oauth Login scripts are not loaded into overloaded pages.

#### Not Found - 404
```python
from easyauth.pages import NotFoundPage

@NotFoundPage.mark()
def custom_not_found_page():
return "Custom 404 Page"

```
!!! TIP
`NotFoundPage` contents is wrapped in an HTMLResponse with a status_code `404`.

#### Forbidden Page - 403
```python
from easyauth.pages import ForbiddenPage

@ForbiddenPage.mark()
def not_allowed_page():
return "Custom 404 Page"
```
#### Login Page & 401
```python
from easyauth.pages import LoginPage

@LoginPage.mark()
def custom_login_page():
return "Custom Login Page"

```

#### Register Page
```python
from easyauth.pages import RegisterPage

@RegisterPage.mark()
def custom_register_page():
return "Custom Register Page"

```

#### Activation Page
```python
from easyauth.pages import ActivationPage

@ActivationPage.mark()
def custom_activation_page():
return "Custom Login Page"

```

### Path Overloads
The default `/login` and 401 redirect path can be overloaded by setting the `default_login_path` on `EasyAuthClient.create()`.

```python
server.auth = await EasyAuthClient.create(
server,
token_server='0.0.0.0',
token_server_port=8090,
auth_secret='abcd1234',
default_permissions={'groups': ['users']},
default_login_path='/v1/internal/login'
)
```
59 changes: 58 additions & 1 deletion docs/server_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,61 @@ $ cat /etc/hosts

![](images/oauth-error.png)

Updating Browser Path to overriden host path, login should then be possible if correctly configured in google console
Updating Browser Path to overriden host path, login should then be possible if correctly configured in google console


### Page Overloads
It is possible to overload the existing login, register, activation, not_found, and forbidden pages using the page specific "overloader". Just like routers, this should be done after an EasyAuthClient is created.

!!! Danger
Consider reviewing what API's are used / required before overloading any existing page. Oauth Login scripts are not loaded into overloaded pages.

#### Not Found - 404
```python
from easyauth.pages import NotFoundPage

@NotFoundPage.mark()
def custom_not_found_page():
return "Custom 404 Page"

```
!!! TIP
`NotFoundPage` contents is wrapped in an HTMLResponse with a status_code `404`.

#### Forbidden Page - 403
```python
from easyauth.pages import ForbiddenPage

@ForbiddenPage.mark()
def not_allowed_page():
return "Custom 404 Page"
```
#### Login Page & 401
```python
from easyauth.pages import LoginPage

@LoginPage.mark()
def custom_login_page():
return "Custom Login Page"

```

#### Register Page
```python
from easyauth.pages import RegisterPage

@RegisterPage.mark()
def custom_register_page():
return "Custom Register Page"

```

#### Activation Page
```python
from easyauth.pages import ActivationPage

@ActivationPage.mark()
def custom_activation_page():
return "Custom Login Page"

```
Loading