Skip to content

Commit d39227e

Browse files
authored
Merge pull request #1 from passwordless/dev
Python SDK
2 parents 24db274 + 9bcac12 commit d39227e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4778
-2
lines changed

.flake8

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[flake8]
2+
show-source = True
3+
doctests = True
4+
exclude =
5+
src/passwordless/__init__.py
6+
venv

.github/workflows/cd.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [created]
6+
7+
jobs:
8+
publish:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
steps:
14+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # 3.6.0
15+
- name: Install poetry
16+
run: pipx install poetry
17+
- name: Set up Python 3.8
18+
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # 4.7.1
19+
with:
20+
python-version: '3.8'
21+
cache: 'poetry'
22+
- name: Configure PYPI
23+
run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
24+
- name: Publish to PYPI
25+
run: poetry publish --build

.github/workflows/ci.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
build-maven:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
steps:
18+
- uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # 3.6.0
19+
- name: Install poetry
20+
run: pipx install poetry
21+
- name: Set up Python 3.8
22+
uses: actions/setup-python@65d7f2d534ac1bc67fcd62888c5f4f3d2cb2b236 # 4.7.1
23+
with:
24+
python-version: '3.8'
25+
cache: 'poetry'
26+
- name: Build
27+
run: poetry install --with dev,test
28+
- name: Run isort
29+
run: poetry run isort . --check-only
30+
- name: Run docformatter
31+
run: poetry run docformatter --in-place --config ./pyproject.toml src/
32+
- name: Run black
33+
run: poetry run black . --check
34+
- name: Run flake8
35+
run: poetry run flake8 .
36+
- name: Run mypy
37+
run: poetry run mypy .
38+
- name: Test
39+
run: poetry run pytest

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,4 @@ cython_debug/
157157
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158158
# and can be added to the global gitignore or merged into this file. For a more nuclear
159159
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160-
#.idea/
160+
.idea/

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/PyCQA/isort
3+
rev: e44834b7b294701f596c9118d6c370f86671a50d # 5.12.0
4+
hooks:
5+
- id: isort
6+
args: ['--settings-path', 'pyproject.toml']
7+
- repo: https://github.com/PyCQA/docformatter
8+
rev: dfefe062799848234b4cd60b04aa633c0608025e # v1.7.5
9+
hooks:
10+
- id: docformatter
11+
additional_dependencies: [tomli]
12+
args: ['--in-place', '--config', './pyproject.toml']
13+
- repo: https://github.com/psf/black
14+
rev: e87737140f32d3cd7c44ede75f02dcd58e55820e # 23.9.1
15+
hooks:
16+
- id: black
17+
- repo: https://github.com/PyCQA/flake8
18+
rev: 7ef0350a439c93166bc8ba89fcc3de6a9a664e6c # 6.1.0
19+
hooks:
20+
- id: flake8
21+
- repo: https://github.com/pre-commit/mirrors-mypy
22+
rev: 08cbc46b6e135adec84911b20e98e5bc52032152 # v1.5.1
23+
hooks:
24+
- id: mypy
25+
require_serial: true
26+
additional_dependencies: [
27+
types-requests>2,
28+
marshmallow>3
29+
]
30+
exclude: tests|examples

README.md

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,113 @@
1-
# passwordless-python
1+
# Passwordless Python SDK
2+
3+
The official [Bitwarden Passwordless.dev](https://passwordless.dev/) Python library, for Python 3+.
4+
5+
## Installation
6+
7+
Install with `python -m pip install passwordless`.
8+
9+
### Dependencies
10+
11+
- [Requests][requests] for HTTP API
12+
- [marshmallow][marshmallow] for JSON (de)serialization
13+
14+
## Getting Started
15+
16+
Follow the [Get started guide][api-docs].
17+
18+
### Create `PasswordlessClient` instance:
19+
20+
```python
21+
from passwordless import (
22+
PasswordlessClient,
23+
PasswordlessClientBuilder,
24+
PasswordlessOptions,
25+
)
26+
27+
28+
class PasswordlessPythonSdkExample:
29+
client: PasswordlessClient
30+
31+
def __init__(self):
32+
options = PasswordlessOptions("your_api_secret")
33+
34+
self.client = PasswordlessClientBuilder(options).build()
35+
36+
```
37+
38+
### Register a passkey
39+
40+
```python
41+
import uuid
42+
from passwordless import PasswordlessClient, RegisterToken, RegisteredToken
43+
44+
45+
class PasswordlessPythonSdkExample:
46+
client: PasswordlessClient
47+
48+
def get_register_token(self, alias: str) -> str:
49+
# Get existing userid from session or create a new user.
50+
user_id = str(uuid.uuid4())
51+
52+
# Options to give the Api
53+
register_token = RegisterToken(
54+
user_id=user_id, # your user id
55+
username=alias, # e.g. user email, is shown in browser ui
56+
aliases=[alias] # Optional: Link this userid to an alias (e.g. email)
57+
)
58+
59+
response: RegisteredToken = self.client.register_token(register_token)
60+
61+
# return this token
62+
return response.token
63+
```
64+
65+
### Verify user
66+
67+
```python
68+
from passwordless import PasswordlessClient, VerifySignIn, VerifiedUser
69+
70+
71+
class PasswordlessPythonSdkExample:
72+
client: PasswordlessClient
73+
74+
def verify_sign_in_token(self, token: str) -> VerifiedUser:
75+
verify_sign_in = VerifySignIn(token)
76+
77+
# Sign the user in, set a cookie, etc,
78+
return self.client.sign_in(verify_sign_in)
79+
```
80+
81+
### Customization
82+
83+
Customize `PasswordlessOptions` by providing `api_secret` with your Application's Api Secret.
84+
You can also change the `api_url` if you prefer to self-host.
85+
86+
Customize `PasswordlessClientBuilder` by providing `session` [requests Session][requests] instance.
87+
88+
### Examples
89+
90+
See [Passwordless Python Example](examples/flask) for Flash Web application.
91+
92+
## Documentation
93+
94+
For a comprehensive list of examples, check out the [API documentation][api-docs].
95+
96+
## Contributing
97+
98+
This library is compatible with Python 3 and requires minimum Python 3.8 installed.
99+
Install [Poetry][poetry] if not already installed.
100+
101+
Activate shell: `poetry shell`
102+
103+
Install dependencies: `poetry install --with dev,test`
104+
105+
Build: `poetry build`
106+
107+
[api-docs]:https://docs.passwordless.dev/guide/get-started.html
108+
109+
[poetry]:https://python-poetry.org/docs/#installation
110+
111+
[requests]:https://requests.readthedocs.io/en/latest/
112+
113+
[marshmallow]:https://marshmallow.readthedocs.io/en/stable/

examples/flask/.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
#.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
.idea/

0 commit comments

Comments
 (0)