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

Feat/django 4 compatibility #12

Open
wants to merge 55 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
fbcea3d
Lcense
atereshkin Apr 3, 2018
5813dd2
Merge branch 'master' of github.com:atereshkin/django-web3-auth
atereshkin May 7, 2018
391278c
Fix typo's in web3auth.js (need to be checked)
delneg Jun 24, 2018
5c97d08
Fix forms to get_user_model
delneg Jun 24, 2018
4900e13
Switch to cookiecutter-djangopackage
delneg Jun 24, 2018
ad4309c
Fixed middleware_classes in example/settings.pu
delneg Jun 24, 2018
bcd62a9
Added things to cover in docs to readme
delneg Jun 24, 2018
413bcf7
Added login_redirect_url to example
delneg Jun 24, 2018
ba8cc0d
added signup template to example, package, urls
delneg Jun 24, 2018
12b2a98
Renamed urls, added login_url param in js
delneg Jun 24, 2018
16bc347
Fix forms, moved validate_eth_address to utils
delneg Jun 24, 2018
22e7513
Revert signup form user model, made backend - case-insensitive
delneg Jun 24, 2018
99aa6f4
Try fix redirect url
delneg Jun 24, 2018
1637fe6
Added missing translation to utils
delneg Jun 25, 2018
e3b9fdb
Added test gif, added it to readme
delneg Jun 26, 2018
19f66bf
Docs, docs, docs
delneg Jun 27, 2018
d8152e8
Added sphinx-rtd-theme to conf.py, requirements_dev.txt
delneg Jun 29, 2018
302793c
PyPi Release
delneg Jun 29, 2018
aeb45f9
Added docs requirements
delneg Jun 29, 2018
97054d3
Replace arrow functions (for compatibility)
delneg Aug 4, 2018
7c5690c
Bump version of rlp to 1.2.0
SukiCZ Mar 15, 2021
95e584c
Merge pull request #1 from SukiCZ/bump_rlp_version
delneg Mar 15, 2021
70d1ae5
Bump version to 0.1.1
delneg Mar 15, 2021
aff2519
Merge remote-tracking branch 'origin/bump_rlp_version'
SukiCZ Mar 15, 2021
4f190a4
Fix to make release
delneg Mar 15, 2021
e9fb87c
Travis happy
SukiCZ Mar 15, 2021
a417b62
Flake8 happy
SukiCZ Mar 15, 2021
e2c32a8
Merge remote-tracking branch 'bearle/master' into travis_happy
SukiCZ Mar 15, 2021
3e7cb8a
Merge pull request #2
delneg Mar 16, 2021
28dc273
Bump to 0.1.2
delneg Mar 16, 2021
d05cc11
Bump to 0.1.3, fix ethereum, add to req's
delneg Mar 23, 2021
1480cad
Try bump to 0.1.4, try fix rlp versions
delneg May 6, 2021
dffb3f0
Added web.js since it is no longer auto added by metamask
Sep 6, 2021
3bbf17a
Merge pull request #5 from hiporox/master
delneg Sep 6, 2021
4d850e8
Bump to 0.1.5, update makefile for release
delneg Sep 6, 2021
433a682
Fixed look ups for URLs
Sep 6, 2021
0c859e6
Merge pull request #6 from hiporox/fix_url_look_ups
delneg Sep 6, 2021
12b6708
Bump to 0.1.6
delneg Sep 6, 2021
a8dbb8b
Fix up leftovers from old django versions
0xteo Sep 15, 2021
7a20664
Refactor login
0xteo Sep 16, 2021
bc27526
Add automatic user creation on signup
0xteo Sep 16, 2021
4105092
Clean up the clutter
0xteo Sep 16, 2021
4c9c832
Add eth address form and model fields
0xteo Sep 27, 2021
6d07803
Add csrftoken autoset
0xteo Sep 27, 2021
02044c5
Add eth transaction fields
0xteo Sep 27, 2021
b9c0157
Fix eth transaction field length
0xteo Sep 27, 2021
4d1fb2e
Return redirect url instead of redirecting
0xteo Sep 30, 2021
285f706
Fix redirects after login
0xteo Sep 30, 2021
d18c4e9
Add automatic username generation if username is required
0xteo Oct 6, 2021
198ce08
refactor: Switch to ECMAScript import/export syntax, remove clutter
0xteo Oct 13, 2021
a715ca9
feat: Add a mock login view when in debug mode
0xteo Nov 11, 2021
2835595
feature: Add boilerplate for user ens name field
0xteo Mar 18, 2022
fe2beb8
Merge pull request #1 from krilarite/feat/ens-name
0xteo Mar 22, 2022
024e6ec
Make django version requirement more flexible
teodorivanov11 Apr 15, 2022
857c089
feat: Update ugettext lazy imports
Apr 23, 2022
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
23 changes: 23 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,rst,ini}]
indent_style = space
indent_size = 4

[*.{html,css,scss,json,yml}]
indent_style = space
indent_size = 2

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
162 changes: 159 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,159 @@
*.pyc
*~
*.tmp
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
__pycache__

# C extensions
*.so

# If you are using PyCharm #
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/gradle.xml
.idea/**/libraries
*.iws /out/

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

-# Mr Developer
-.mr.developer.cfg
-.project
-.pydevproject

-# Sphinx
-docs/_build

-# Complexity
-output/*.html
-output/*/index.html

-example/db.sqlite3
43 changes: 43 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
MIT License

Copyright (c) 2018 Alexander Tereshkin

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.

MIT License

Copyright (c) 2018 Bearle

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.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
recursive-include web3auth *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
87 changes: 66 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,78 @@
# Django-Web3-Auth
# django-web3-auth

django-web3-auth is a pluggable Django app that enables login/signup via an Ethereum wallet (a la CryptoKitties). The user authenticates themselves by digitally signing the session key with their wallet's private key.
django-web3-auth is a pluggable Django app that enables login/signup via an Ethereum wallet (specifically MetaMask).
The user authenticates themselves by digitally signing the session key with their wallet's private key.

Use with django >= 3.2.0, python >= 3.9

## Installation

django-web3-auth has no releases yet, you'll need to install it from repository:
## Quickstart
Install django-web3-auth with pip:
```bash
pip install https://github.com/atereshkin/django-web3-auth/archive/master.zip
pip install git+ssh://git@github.com/krilarite/django-web3-auth.git
```

You will also need [Web3.js](https://github.com/ethereum/web3.js) included in your pages.

## Usage

1. Add `'web3auth'` to the `INSTALLED_APPS` setting
2. Set `'web3auth.backend.Web3Backend'` as your authentication backend:
Add it to your INSTALLED_APPS:
```python
INSTALLED_APPS = [
...
'web3auth',
...
]
```
Set 'web3auth.backend.Web3Backend' as your authentication backend:
```python
AUTHENTICATION_BACKENDS = ['web3auth.backend.Web3Backend']
AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'web3auth.backend.Web3Backend'
]
```
3. Bind some URLs to `web3auth.views.login_view` and `web3auth.views.signup_view`. Both views take an optional `template_name` argument.
Set a field from the User model for storing the users' ETH address:
```python
from django.conf.urls import url

from web3auth import views as web3auth_views
WEB3AUTH_USER_ADDRESS_FIELD = 'username'
```
Add Django-Web3-Auth's URL patterns:
```python
from web3auth import urls as web3auth_urls

urlpatterns = [
url(r'^login/$', web3auth_views.login_view, {'template_name' : 'login.html'}, name='login'),
url(r'^signup/$', web3auth_views.signup_view, name='signup'),
...
path('', include(web3auth_urls)),
...
]
```
Add some javascript to handle login:
```html
<script src="{% static 'web3auth/js/web3.js' %}"></script>
<script src="{% static 'web3auth/js/web3auth.js' %}"></script>
```
Implement a login button:
```html
<button type="button" onclick="connectWallet()">Connect wallet</button>
<script>
async function connectWallet() {
var authUrl = "{% url 'web3auth:web3auth_api' %}";
await authWeb3(authUrl, console.log, console.log, console.log, console.log, console.log, function (resp) {
window.location.replace(resp.redirect_url);
});
};
</script>
```
MetaMask will prompt you to sign a message and you'll be logged in afterwards.


## Contributing
Clone the project
```bash
git clone [email protected]:krilarite/django-web3-auth.git
```
Set up a virtualenv
```
mkvirtualenv -p /usr/bin/python3.9 -a `pwd` django-web3-auth
pip install -r requirements.txt
```
Use the example project for testing
```bash
cd example
python manage.py migrate
python manage.py runserver
```
4. Code your templates for login and signup pages. Example code can be found in [login.html](web3auth/templates/web3auth/login.html) and [signup.html](web3auth/templates/web3auth/signup.html)
Navigate to `localhost:8000/login` and you'll see a login page.
25 changes: 25 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Example Project for web3auth

This example is provided as a convenience feature to allow potential users to try the app straight from the app repo without having to create a django project.

It can also be used to develop the app in place.

To run this example, follow these instructions:

1. Clone the repository
2. Navigate to the `example` directory
3. Install the requirements for the package (probably in a virtualenv):

pip install -r requirements.txt

4. Make and apply migrations

python manage.py makemigrations

python manage.py migrate

5. Run the server

python manage.py runserver

6. Access from the browser at `http://127.0.0.1:8000`
File renamed without changes.
Loading