Skip to content

Commit

Permalink
feat(flask): adding flask decorators as a package extra (#291)
Browse files Browse the repository at this point in the history
* feat(flask): adding flask decorators as a package extra

* readme and omit coverage
  • Loading branch information
omercnet committed Sep 21, 2023
1 parent 6fc8917 commit 6d4d6e0
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 169 deletions.
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ repos:
rev: 6.1.0
hooks:
- id: flake8
additional_dependencies: [Flake8-pyproject]
- repo: https://github.com/python-poetry/poetry
rev: 1.6.1
hooks:
Expand Down Expand Up @@ -69,10 +70,3 @@ repos:
language: system
files: ^(.*requirements.*\.txt|setup\.cfg|setup\.py|pyproject\.toml|liccheck\.ini)$
pass_filenames: false
- id: tox
name: Run tests with tox
description: Run tox to check that all tests pass
entry: poetry run tox -p
language: system
files: ^(.*\.py)$
pass_filenames: false
11 changes: 11 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"recommendations": [
"ms-python.python",
"ms-python.black-formatter",
"ms-python.flake8",
"ms-python.isort",
"ms-python.vscode-pylance",
"ms-python.mypy-type-checker",
"bodil.prettier-toml",
]
}
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"python.testing.pytestArgs": [
"tests"
],
"mypy.runUsingActiveInterpreter": true,
"flake8.importStrategy": "fromEnvironment",
"mypy-type-checker.importStrategy": "fromEnvironment",
"isort.importStrategy": "fromEnvironment",
"black-formatter.importStrategy": "fromEnvironment",
}
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Install the package with:
pip install descope
```

#### If you would like to use the Flask decorators, make sure to install the Flask extras:

```bash
pip install descope[Flask]
```

## Setup

A Descope `Project ID` is required to initialize the SDK. Find it on the
Expand Down Expand Up @@ -795,10 +801,13 @@ updated_jwt = descope_client.mgmt.jwt.update_jwt(
```

# Note 1: The generate code/link functions, work only for test users, will not work for regular users.

# Note 2: In case of testing sign-in / sign-up operations with test users, need to make sure to generate the code prior calling the sign-in / sign-up operations.

# Embedded links can be created to directly receive a verifiable token without sending it.

# This token can then be verified using the magic link 'verify' function, either directly or through a flow.

token = descope_client.mgmt.user.generate_embedded_link("[email protected]", {"key1":"value1"})

### Search Audit
Expand Down Expand Up @@ -885,8 +894,9 @@ You can find various usage samples in the [samples folder](https://github.com/de
## Run Locally

### Prerequisites
- Python 3.7 or higher
- [Poetry](https://python-poetry.org) installed

- Python 3.7 or higher
- [Poetry](https://python-poetry.org) installed

### Install dependencies

Expand All @@ -897,11 +907,13 @@ poetry install
### Run tests

Running all tests:

```bash
poetry run pytest tests
```

Running all tests with coverage:

```bash
poetry run pytest --junitxml=/tmp/pytest.xml --cov-report=term-missing:skip-covered --cov=descope tests/ --cov-report=xml:/tmp/cov.xml
```
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from __future__ import annotations

import datetime
import uuid
from functools import wraps

from flask import Response, _request_ctx_stack, redirect, request

from descope import (
from .. import (
COOKIE_DATA_NAME,
REFRESH_SESSION_COOKIE_NAME,
REFRESH_SESSION_TOKEN_NAME,
Expand All @@ -13,8 +15,8 @@
AuthException,
DeliveryMethod,
)
from descope.descope_client import DescopeClient
from descope.exceptions import ERROR_TYPE_INVALID_ARGUMENT
from ..descope_client import DescopeClient
from ..exceptions import ERROR_TYPE_INVALID_ARGUMENT


def set_cookie_on_response(response: Response, token: dict, cookie_data: dict):
Expand All @@ -38,7 +40,7 @@ def set_cookie_on_response(response: Response, token: dict, cookie_data: dict):
)


def descope_signup_otp_by_email(descope_client):
def descope_signup_otp_by_email(descope_client: DescopeClient):
"""
Sign-up new user, using email to verify the OTP
"""
Expand All @@ -64,7 +66,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_signin_otp_by_email(descope_client):
def descope_signin_otp_by_email(descope_client: DescopeClient):
"""
Sign-in existing user, using email to verify OTP
"""
Expand All @@ -89,7 +91,12 @@ def decorated(*args, **kwargs):
return decorator


def descope_validate_auth(descope_client, permissions=None, roles=None, tenant=""):
def descope_validate_auth(
descope_client: DescopeClient,
permissions: list[str] | None = None,
roles: list[str] | None = None,
tenant="",
):
"""
Test if Access Token is valid
"""
Expand Down Expand Up @@ -152,7 +159,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_verify_code_by_email(descope_client):
def descope_verify_code_by_email(descope_client: DescopeClient):
"""
Verify code by email decorator
"""
Expand Down Expand Up @@ -195,7 +202,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_verify_code_by_phone(descope_client):
def descope_verify_code_by_phone(descope_client: DescopeClient):
"""
Verify code by email decorator
"""
Expand Down Expand Up @@ -238,7 +245,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_verify_code_by_whatsapp(descope_client):
def descope_verify_code_by_whatsapp(descope_client: DescopeClient):
"""
Verify code by whatsapp decorator
"""
Expand Down Expand Up @@ -281,7 +288,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_signup_magiclink_by_email(descope_client, uri):
def descope_signup_magiclink_by_email(descope_client: DescopeClient, uri: str):
"""
Signup new user using magiclink via email
"""
Expand All @@ -307,7 +314,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_signin_magiclink_by_email(descope_client, uri):
def descope_signin_magiclink_by_email(descope_client: DescopeClient, uri: str):
"""
Signin using magiclink via email
"""
Expand All @@ -332,7 +339,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_verify_magiclink_token(descope_client):
def descope_verify_magiclink_token(descope_client: DescopeClient):
"""
Verify magiclink token
"""
Expand Down Expand Up @@ -370,7 +377,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_logout(descope_client):
def descope_logout(descope_client: DescopeClient):
"""
Logout
"""
Expand Down Expand Up @@ -426,7 +433,7 @@ def decorated(*args, **kwargs):
return decorator


def descope_full_login(project_id, flow_id, success_redirect_url):
def descope_full_login(project_id: str, flow_id: str, success_redirect_url: str):
"""
Descope Flow login
"""
Expand Down
Loading

0 comments on commit 6d4d6e0

Please sign in to comment.