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

Prepare next release #342

Merged
merged 71 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
4e090ca
Fix: library also compatible with Django 4.0
belugame Jan 31, 2022
11c1096
fix migrate zero
lubaskinc0de Jul 18, 2022
0d95bf4
Merge pull request #1 from lubaskinc0de/lubaskinc0de-patch-1
lubaskinc0de Jul 18, 2022
04c15fd
Updated README.md
Adegitetaiwo Jul 26, 2022
1796ad8
Undated index.md
Adegitetaiwo Jul 26, 2022
1f61144
docu: clearify behavior of TOKEN_LIMIT_PER_USER (#228)
Rotzbua Aug 15, 2022
78fe0c6
use hashlib instead of cryptography (#230)
Rotzbua Aug 15, 2022
dc870df
Allowed usage of custom AuthToken based on knox.AbstractAuthToken (#275)
Khalidm98 Aug 16, 2022
3a1bc58
feat: add token prefix option (#272)
max-wittig Aug 24, 2022
dff944e
Add Django 4.1 to test
Rotzbua Aug 30, 2022
19e18cf
Add deprecation note to `USE_L10N`
Rotzbua Aug 30, 2022
3651a07
update AuthTokenManager to support custom values
brukberhane Oct 17, 2022
d2fc245
Remove legacy code from Python 2
Rotzbua Jan 8, 2023
6828738
[doc] improve readability of example code
Rotzbua Nov 15, 2020
1a9d833
Add python 3.11 to test
Rotzbua Jan 5, 2023
2838c5c
Move isort, flake8 test to Python 3.10
Rotzbua Jan 8, 2023
af85fc6
Bump GH Actions versions
Rotzbua Jan 8, 2023
9e94bb3
GitHub Actions: Deprecating save-state and set-output commands
Rotzbua Jan 8, 2023
767e7b8
Update `markdown` dependency
Rotzbua Jan 13, 2023
6f0c7a9
Remove legacy compat lib `six`
Rotzbua Jan 13, 2023
761dad2
Enable customizing login/logout responses
c-w Jan 16, 2023
bc82a16
Update link to documentation
JackMorganNZ Aug 3, 2023
a59a052
Merge pull request #305 from JackMorganNZ/update-documentation-link
giovannicimolin Aug 15, 2023
3ce2bc5
docs: Update references to point to Jazzband
giovannicimolin Aug 15, 2023
efcfdcb
Merge pull request #307 from jazzband/giovannicimolin/jazzband-setup
giovannicimolin Aug 15, 2023
88b4176
test: Set up pre-commit hooks and fix quality nits
giovannicimolin Aug 15, 2023
5b936a7
test: Add coverage and codecov bot
giovannicimolin Aug 15, 2023
f0261b2
Merge pull request #308 from jazzband/giovannicimolin/more-jazzband-s…
giovannicimolin Aug 15, 2023
1a57338
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Aug 21, 2023
52b5458
Merge pull request #309 from jazzband/pre-commit-ci-update-config
giovannicimolin Aug 21, 2023
17c1c09
Merge pull request #236 from Rotzbua/doc_readability
giovannicimolin Aug 21, 2023
a976616
Merge pull request #293 from Rotzbua/update_gh_actions
giovannicimolin Aug 21, 2023
ae93641
Merge branch 'develop' into remove_legacy_py2
AdamDonna Sep 25, 2023
6683306
Fix migrations when used in condition with a custom DB.
niall-madecurious Oct 8, 2023
72e91e4
Merge pull request #294 from Rotzbua/remove_legacy_py2
giovannicimolin Oct 10, 2023
bc7c284
Merge pull request #313 from mediasuitenz/fix-migrations-on-custom-db
giovannicimolin Oct 10, 2023
b02a155
fix(docs): add warning of migration to `4.2.0`
Rotzbua Jun 17, 2022
03272c9
fix(docs): correct typo
Rotzbua Oct 10, 2023
00a457b
Merge pull request #316 from Rotzbua/fix_typo
giovannicimolin Oct 12, 2023
c64c906
Merge pull request #270 from lubaskinc0de/develop
giovannicimolin Oct 12, 2023
cd5dcb6
Merge pull request #268 from Rotzbua/patch-1
giovannicimolin Oct 16, 2023
43d983d
Add docs for get_post_response
c-w Oct 17, 2023
ffd9171
Merge pull request #296 from c-w/customize-logout-response
giovannicimolin Oct 17, 2023
f33c1af
feat(ci): add django4.2; remove eol django4.0
Rotzbua Oct 10, 2023
18b4775
feat(ci): add django5.0; add python3.12; remove eol django4.1
Rotzbua Dec 10, 2023
22d787e
feat: add typing
Rotzbua Dec 17, 2023
d860b41
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] Jan 8, 2024
df5580e
Merge pull request #324 from Rotzbua/feat_add_typing
dekkers Jan 12, 2024
d996f3e
Merge pull request #322 from jazzband/pre-commit-ci-update-config
dekkers Jan 12, 2024
dd7b062
Merge pull request #321 from Rotzbua/feat_gh_django5
dekkers Jan 12, 2024
4015993
refactor: use `self.authenticate_header()` to get auth header
luqmansen Jan 26, 2024
af386f9
chore(migration): use f-string
Rotzbua Dec 17, 2023
ad1eca6
Merge pull request #317 from Rotzbua/chore_migration
giovannicimolin Jan 27, 2024
271179a
Merge pull request #329 from luqmansen/develop
giovannicimolin Jan 28, 2024
9b34168
Fix README.md
nbro Apr 1, 2024
0940325
Merge pull request #333 from nbro/patch-1
dekkers Apr 1, 2024
7d21736
Avoid importing `django.test` in main code
angusholder Apr 26, 2024
87da8d2
Merge branch 'develop' into patch-1
johnraz May 2, 2024
ef6e9d2
Merge pull request #273 from Adegitetaiwo/patch-1
johnraz May 2, 2024
3dc5ba3
Merge pull request #274 from Adegitetaiwo/patch-2
johnraz May 2, 2024
cde8a88
feat: Add action to build and deploy pages to GH-Pages
giovannicimolin May 3, 2024
65c8ffd
Merge pull request #343 from jazzband/giovanni/gh-pages-ci-job
giovannicimolin May 3, 2024
88de7b4
Merge pull request #335 from angusholder/patch-1
giovannicimolin May 7, 2024
f7eae69
Remove flake8 and isort from tox config
calumy May 4, 2024
01c1de4
Merge pull request #346 from calumy/remove-linting-from-testing
johnraz May 9, 2024
0113d42
Merge pull request #287 from brukberhane/develop
johnraz Jun 17, 2024
a2edb24
Add changelog entries for release 4.3.0
johnraz Jul 1, 2024
35382ea
Merge remote-tracking branch 'origin/master' into johnraz-add-changel…
johnraz Jul 1, 2024
94727e9
Merge pull request #355 from jazzband/johnraz-add-changelog-for-release
giovannicimolin Jul 1, 2024
eeed217
docs(changelog): bump to 5.0.0, add token warning
max-wittig Jul 9, 2024
95a8fb3
Merge pull request #358 from max-wittig/patch-1
johnraz Jul 9, 2024
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
11 changes: 11 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coverage:
status:
project:
default: false
tests:
paths: tests
informational: true
knox:
paths: knox
informational: true
patch: off
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
branch = True
source = knox
omit =
*/migrations/*
34 changes: 34 additions & 0 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish Docs to GitHub Pages

permissions:
contents: write

on:
push:
branches:
- develop

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.x

- name: Install dependencies
run: pip install mkdocs-material

- name: Build docs
run: mkdocs build

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
personal_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./site
18 changes: 12 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ jobs:
fail-fast: false
max-parallel: 5
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Get pip cache dir
id: pip-cache
run: |
echo "::set-output name=dir::$(pip cache dir)"
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT

- name: Cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key:
Expand All @@ -36,8 +36,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions
python -m pip install --upgrade tox tox-gh-actions coverage

- name: Tox tests
run: |
tox -v

- name: Generate coverage XML report
run: coverage xml

- name: Codecov
uses: codecov/codecov-action@v3
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,6 @@ docs/_build/
target/
db.sqlite3
site/

# PyCharm Project
.idea
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
hooks:
- id: flake8
26 changes: 24 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
## 5.0.0
- Tokens created prior to this release will no longer work
- Fix migration reverse flow, enable migrate 0
- Various documentation fixes and improvements
- Drop `cryptography` in favor of hashlib
- Make custom AuthModel work
- Token prefix can be set in the setttings
- Drop support for Django 4.0
- Add support for Dango 4.2, 5.0 and Python 3.11 and 3.12
- Cleanup legacy Python 2.0 code
- Fix isort, flake8 usage for Python 3.10 in the test suite
- Update Github actions version
- Upgrade markdown dependency
- Get rid of the `six` library
- Add custom login / logout response support
- Join the jazzband organization
- Add pre-commit hooks
- Add tracking of tests code coverage
- Fix migrations when used in condition with a custom DB
- Improve typing
- Use `self.authenticate_header()` in `authenticate()` method to get auth header prefix

## 4.2.0
- compatibility with Python up to 3.10 and Django up to 3.2
- compatibility with Python up to 3.10 and Django up to 4.0
- integration with github CI instead of travis
- Migration: "salt" field of model "AuthToken" is removed
- Migration: "salt" field of model "AuthToken" is removed, WARNING: invalidates old tokens!

## 4.1.0

Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[![Jazzband](https://jazzband.co/static/img/jazzband.svg)](https://jazzband.co/)

This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) and follow the [guidelines](https://jazzband.co/about/guidelines).
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
django-rest-knox
================

[![image](https://github.com/James1345/django-rest-knox/workflows/Test/badge.svg?branch=develop)](https://github.com/James1345/django-rest-knox/actions)
[![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/)
[![image](https://github.com/jazzband/django-rest-knox/workflows/Test/badge.svg?branch=develop)](https://github.com/jazzband/django-rest-knox/actions)

Authentication Module for django rest auth
Authentication module for Django rest auth.

Knox provides easy to use authentication for [Django REST
Knox provides easy-to-use authentication for [Django REST
Framework](https://www.django-rest-framework.org/) The aim is to allow
for common patterns in applications that are REST based, with little
for common patterns in applications that are REST-based, with little
extra effort; and to ensure that connections remain secure.

Knox authentication is token based, similar to the `TokenAuthentication`
built in to DRF. However, it overcomes some problems present in the
Knox authentication is token-based, similar to the `TokenAuthentication`
built into DRF. However, it overcomes some problems present in the
default implementation:

- DRF tokens are limited to one per user. This does not facilitate
Expand All @@ -23,13 +24,14 @@ default implementation:
client to have its own token which is deleted on the server side
when the client logs out.

Knox also provides an option for a logged in client to remove *all*
Knox also provides an option for a logged-in client to remove *all*
tokens that the server has - forcing all clients to re-authenticate.

- DRF tokens are stored unencrypted in the database. This would allow
an attacker unrestricted access to an account with a token if the
an attacker unrestricted access to an account with a token if the
database were compromised.


Knox tokens are only stored in a secure hash form (like a password). Even if the
database were somehow stolen, an attacker would not be able to log
in with the stolen credentials.
Expand All @@ -39,12 +41,11 @@ default implementation:
the app settings (default is 10 hours.)

More information can be found in the
[Documentation](https://james1345.github.io/django-rest-knox/)
[Documentation](https://jazzband.github.io/django-rest-knox/)

# Run the tests locally

If you need to debug a test locally and if you have [docker](https://www.docker.com/) installed:

If you need to debug a test locally and if you have [docker](https://www.docker.com/) installed,
simply run the ``./docker-run-tests.sh`` script and it will run the test suite in every Python /
Django versions.

Expand All @@ -55,7 +56,7 @@ Python / Django versions a bit more tricky.

Our documentation is generated by [Mkdocs](https://www.mkdocs.org).

You can refer to their documentation on how to install it locally.
You can refer to their [documentation](https://www.mkdocs.org/user-guide/installation/) on how to install it locally.

Another option is to use `mkdocs.sh` in this repository.
It will run mkdocs in a [docker](https://www.docker.com/) container.
Expand Down
18 changes: 8 additions & 10 deletions docs/auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,17 @@ If it is your only default authentication class, remember to overwrite knox's Lo

For instance, you can authenticate users using Basic Authentication by simply overwriting knox's LoginView and setting BasicAuthentication as one of the acceptable authentication classes, as follows:

**views.py:**
```python

views.py:

from knox.views import LoginView as KnoxLoginView
from rest_framework.authentication import BasicAuthentication

class LoginView(KnoxLoginView):
authentication_classes = [BasicAuthentication]
```

urls.py:

**urls.py:**
```python
from knox import views as knox_views
from yourapp.api.views import LoginView

Expand All @@ -75,10 +74,8 @@ You can use any number of authentication classes if you want to be able to authe

If you decide to use Token Authentication as your only authentication class, you can overwrite knox's login view as such:

**views.py:**
```python

views.py:

from django.contrib.auth import login

from rest_framework import permissions
Expand All @@ -94,9 +91,10 @@ class LoginView(KnoxLoginView):
user = serializer.validated_data['user']
login(request, user)
return super(LoginView, self).post(request, format=None)
```

urls.py:

**urls.py:**
```python
from knox import views as knox_views
from yourapp.api.views import LoginView

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Django-Rest-Knox
Knox provides easy to use authentication for [Django REST Framework](https://www.django-rest-framework.org/)
Knox provides easy-to-use authentication for [Django REST Framework](https://www.django-rest-framework.org/)
The aim is to allow for common patterns in applications that are REST based,
with little extra effort; and to ensure that connections remain secure.

Knox authentication is token based, similar to the `TokenAuthentication` built
in to DRF. However, it overcomes some problems present in the default implementation:
into DRF. However, it overcomes some problems present in the default implementation:

- DRF tokens are limited to one per user. This does not facilitate securely
signing in from multiple devices, as the token is shared. It also requires
Expand Down
25 changes: 3 additions & 22 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,8 @@

## Requirements

Knox depends on `cryptography` to provide bindings to `OpenSSL` for token generation.
This requires the OpenSSL build libraries to be available.

### Windows
Cryptography is a statically linked build, no extra steps are needed.

### Linux
`cryptography` should build very easily on Linux provided you have a C compiler,
headers for Python (if you’re not using `pypy`), and headers for the OpenSSL and
`libffi` libraries available on your system.

Debian and Ubuntu:
```bash
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev python-dev
```

Fedora and RHEL-derivatives:
```bash
sudo yum install gcc libffi-devel python-devel openssl-devel
```
For other systems or problems, see the [cryptography installation docs](https://cryptography.io/en/latest/installation/)
Knox depends on pythons internal library `hashlib` to provide bindings to `OpenSSL` or uses
an internal implementation of hashing algorithms for token generation.

## Installing Knox
Knox should be installed with pip
Expand Down Expand Up @@ -59,7 +40,7 @@ REST_FRAMEWORK = {

- If you set TokenAuthentication as the only default authentication class on the second step, [override knox's LoginView](auth.md#global-usage-on-all-views) to accept another authentication method and use it instead of knox's default login view.

- Apply the migrations for the models
- Apply the migrations for the models.

```bash
python manage.py migrate
Expand Down
Loading
Loading