Skip to content
This repository has been archived by the owner on Aug 3, 2024. It is now read-only.

Commit

Permalink
Updated README, added LICENSE, updated requirements and tox, added Gi…
Browse files Browse the repository at this point in the history
…thub Actions.
  • Loading branch information
oscarychen committed Jan 13, 2022
1 parent c19c06d commit 4f98e48
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 70 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Test

on: [ push, pull_request ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
max-parallel: 5
matrix:
python-version: [ '3.8', '3.9', '3.10' ]

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

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install --upgrade tox tox-gh-actions
- name: Test with Tox
run: tox
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Oscar Y Chen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
62 changes: 10 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ and [Django Oauth Toolkit](https://github.com/jazzband/django-oauth-toolkit).

#### Motivation

I was using django-oauth-toolkit in a project, but I wanted the refresh tooken to be handled by a HttpOnly cookie, while
having the access token to be continue sent via request/response body.
I was using django-oauth-toolkit in a project, but I wanted the refresh token to be handled by a HttpOnly cookie, while
continue having the access token sent via request/response body.

## Quick start

Expand All @@ -19,17 +19,13 @@ pip install django-oauth-toolkit-cookie-refresh

Or, install from source:

```commandline
pip install git+https://github.com/oscarychen/django-oauth-toolkit-cookie-refresh.git
```

Set
up [django-oauth-toolkit and django REST framework](https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html#step-1-minimal-setup):
up [django-oauth-toolkit and django REST framework](https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html#step-1-minimal-setup) if you haven't already:

```python
INSTALLED_APPS = (
'django.contrib.admin',
...
...,
'oauth2_provider',
'rest_framework',
)
Expand All @@ -46,7 +42,7 @@ REST_FRAMEWORK = {
Include the oauth_toolkit_cookie_refresh URLconf in your project urls.py:

```python
path('auth/', include('oauth_toolkit_cookie_refresh.urls')),
path('auth/', include('oauth_toolkit_cookie_refresh.urls')),
```

## Settings
Expand All @@ -65,53 +61,15 @@ You can modify these settings by specifying them in the settings for django-oaut

```python
OAUTH2_PROVIDER = {
...,
"ACCESS_TOKEN_EXPIRE_SECONDS": 300,
"REFRESH_TOKEN_EXPIRE_SECONDS": 36000,
"REFRESH_COOKIE_NAME": "refresh_token",
"REFRESH_COOKIE_PATH": "/auth",
...
"ACCESS_TOKEN_EXPIRE_SECONDS": 300,
"REFRESH_TOKEN_EXPIRE_SECONDS": 36000,
"REFRESH_COOKIE_NAME": "refresh_token",
"REFRESH_COOKIE_PATH": "/auth",
...
}
```

If you want to use a different path for authentication than the default path, you should provide the setting
in `REFRESH_COOKIE_PATH`, using a string with leading slash `/`; while provide the same path in URLconf but with a
trailing slash `/`.

## Development

To continue develope this package, I've included a `requirements.txt` and `env_setup.sh` to help you get up and running.

With the appropriate Python(ie: Python 3.8), run the following to set up a Python virtual environment in project
directory:

```commandline
source env_setup.py
```

which also creates a `activate.sh`. and then activate the environment by running:

```commandline
source activate.sh
```

To include this package symbolically in another environment (for development):

```commandline
pip install -e PATH_TO_PACKAGE_DIRECTORY
```

Automated testing

```commandline
tox
```

Build/distribution:

```commandline
python setup.py sdist bdist_wheel
twine check dist/*
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
twine upload dist/*
```
6 changes: 3 additions & 3 deletions env_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ deactivate

echo "Creating activate.sh..."
touch activate.sh
echo >>activate.sh
echo > activate.sh
echo "# Created by env_setup.sh, modify the environment variables below if needed.">>activate.sh
echo "source $ENVPATH">>activate.sh
echo >>activate.sh
echo "source $ENVPATH">> activate.sh
echo >> activate.sh

echo 'Finished setting up environment.'
echo 'To activate environment, run `source activate.sh`.'
Expand Down
3 changes: 2 additions & 1 deletion manifest.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
include README.md
recursive-include docs *
recursive-include docs *
recursive-exclude tests *
13 changes: 5 additions & 8 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
autopep8==1.6.0
Django==3.2.10
django-oauth-toolkit==1.6.0
djangorestframework==3.13.1
pylint==2.12.2
pylint-django==2.4.4
tox==3.24.4
wheel==0.37.1
Django>=2.2
django-oauth-toolkit>=1.5.0
djangorestframework>=3.10
tox>=3.24
wheel>=0.37
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[metadata]
name = django-oauth-toolkit-cookie-refresh
version = 0.1
version = 1.0.0
description = A Django app that facilitates authentication using cookie-based refresh token
long_description = file: README.md
url = https://github.com/oscarychen/django-oauth-toolkit-cookie-refresh
author = Oscar Chen
author_email = [email protected]
license = BSD-3-Clause
license = MIT
classifiers =
Environment :: Web Environment
Framework :: Django
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from setuptools import setup
from setuptools import setup, find_packages

setup(long_description_content_type='text/markdown')
setup(
long_description_content_type='text/markdown',
packages=find_packages(exclude=("tests",)),
)
13 changes: 11 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
[tox]
envlist =
lint-py{38}
django40-py{39,38}
django32-py{38,39}
django40-py{310,39,38}
django32-py{310,38,39}
django22-py{39,38}

skip_missing_interpreters =
true

[gh-actions]
python =
3.8: py38
3.9: py39
3.10: py310

[testenv]
deps =
{[base]deps}
Expand Down

0 comments on commit 4f98e48

Please sign in to comment.