Skip to content

Commit 8919b9c

Browse files
committed
Fix tox, docs
Replace jQuery.trim in scatterauth.js Added explanatory gif
1 parent ad17ee6 commit 8919b9c

File tree

10 files changed

+67
-69
lines changed

10 files changed

+67
-69
lines changed

CONTRIBUTING.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Ready to contribute? Here's how to set up `django-scatter-auth` for local develo
7777
5. When you're done making changes, check that your changes pass flake8 and the
7878
tests, including testing other Python versions with tox::
7979

80-
$ flake8 web3auth tests
80+
$ flake8 scatterauth tests
8181
$ python setup.py test
8282
$ tox
8383

@@ -109,4 +109,4 @@ Tips
109109

110110
To run a subset of tests::
111111

112-
$ python -m unittest tests.test_web3auth
112+
$ python -m unittest tests.test_scatterauth

HISTORY.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
History
44
-------
55

6-
0.1.0 (2018-08-06)
6+
0.1.0 (2018-08-13)
77
++++++++++++++++++
88

99
* First release on PyPi

README.rst

+24-30
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ django-scatter-auth
1111
.. image:: https://codecov.io/gh/Bearle/django-scatter-auth/branch/master/graph/badge.svg
1212
:target: https://codecov.io/gh/Bearle/django-scatter-auth
1313

14-
django-scatter-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.
14+
django-scatter-auth is a pluggable Django app that enables login/signup via Scatter (EOS extension wallet). The user authenticates themselves by digitally signing the hostname with their wallet's private key.
1515

16-
.. image:: https://github.com/Bearle/django-scatter-auth/blob/master/docs/_static/web3_auth_test.gif?raw=true
16+
.. image:: https://github.com/Bearle/django-scatter-auth/blob/master/docs/_static/django_scatter_auth_test2.gif?raw=true
1717

1818
Documentation
1919
-------------
@@ -32,10 +32,10 @@ There is a README file for you to check, also.
3232
Features
3333
--------
3434

35-
* Web3 API login, signup
36-
* Web3 Django forms for signup, login
37-
* Checks ethereum address validity
38-
* Uses random token signing as proof of private key posession
35+
* Scatter API login, signup
36+
* Scatter Django forms for signup, login
37+
* Checks signature (validation)
38+
* Uses hostname signing as proof of private key posession
3939
* Easy to set up and use (just one click)
4040
* Custom auth backend
4141
* VERY customizable - uses Django settings, allows for custom User model
@@ -64,7 +64,7 @@ Set `'scatterauth.backend.ScatterAuthBackend'` as your authentication backend:
6464
'django.contrib.auth.backends.ModelBackend',
6565
'scatterauth.backend.ScatterAuthBackend'
6666
]
67-
Set your User model's field to use as ETH address provider:
67+
Set your User model's field to use as public key storage:
6868

6969
.. code-block:: python
7070
@@ -100,26 +100,20 @@ Add some javascript to handle login:
100100

101101
.. code-block:: javascript
102102
103-
function startLogin() {
104-
if (typeof web3 !== 'undefined') {
105-
checkWeb3(function (loggedIn) {
106-
if (!loggedIn) {
107-
alert("Please unlock your web3 provider (probably, Metamask)")
108-
} else {
109-
var login_url = '{% url 'scatterauth_login_api' %}';
110-
web3Login(login_url, console.log, console.log, console.log, console.log, console.log, function (resp) {
111-
console.log(resp);
112-
window.location.replace(resp.redirect_url);
113-
});
114-
}
103+
var login_url = '{% url 'scatterauth_login_api' %}';
104+
document.addEventListener('scatterLoaded', scatterExtension => {
105+
console.log('scatter loaded');
106+
if (scatter.identity) {
107+
console.log("Identity found");
108+
loginWithAuthenticate(login_url,console.log,console.log,console.log,console.log, function (resp) {
109+
window.location.replace(resp.redirect_url);
115110
});
116-
117111
} else {
118-
alert('web3 missing');
112+
console.log('identity not found, have to signup');
119113
}
120-
}
114+
});
121115
122-
You can access signup using {% url 'scatterauth_signup' %}.
116+
You can access signup using {% url 'scatterauth_signup' %} and API signup using {% url 'scatterauth_signup_api' %}.
123117

124118
If you have any questions left, head to the example app https://github.com/Bearle/django-scatter-auth/tree/master/example
125119

@@ -128,22 +122,22 @@ If you have any questions left, head to the example app https://github.com/Bearl
128122
Important details and FAQ
129123
-------------------------
130124

131-
1. *If you set a custom address field (SCATTERAUTH_USER_PUBKEY_FIELD), it MUST be unique (unique=True).*
125+
1. *If you set a custom public key field (SCATTERAUTH_USER_PUBKEY_FIELD), it MUST be unique (unique=True).*
132126

133-
This is needed because if it's not, the user can register a new account with the same address as the other one,
127+
This is needed because if it's not, the user can register a new account with the same public key as the other one,
134128
meaning that the user can now login as any of those accounts (sometimes being the wrong one).
135129

136130
2. *How do i deal with user passwords or Password is not set*
131+
137132
There should be some code in your project that generates a password using ``User.objects.make_random_password`` and sends it to a user email.
138133
Or, even better, sends them a 'restore password' link.
139134
Also, it's possible to copy signup_view to your project, assign it a url, and add the corresponding lines to set some password for a user.
140135

141-
3. *Why do i have to sign a message? It's not needed in MyEtherWallet or other DApps!*
136+
3. *Why don't i have to sign a message? It's needed in django-web3-auth, how this app is secure?*
142137

143-
The main reason is that when using a DApp, you most likely don't have an account on the website, it's accessible only with web3 (Metamask).
144-
When using web3 only to sign into user account, it is necessary to prove your identity with a private key (e.g. sign a random message),
145-
because when we have backend we can't trust any user just by his knowledge of the public address.
146-
Signed message proves that user possesses the private key, associated with the address.
138+
This app uses scatter's ``authenticate`` function to handle message signing - hostname being the signed message.
139+
This means that the user & the client share knowledge of the original message and the server can verify
140+
client's possession of the private key corresponding to the public key.
147141

148142

149143
Running Tests
3.36 MB
Loading

docs/index.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
You can adapt this file completely to your liking, but it should at least
44
contain the root `toctree` directive.
55
6-
Welcome to Django-Web3-Auth's documentation!
6+
Welcome to Django-Scatter-Auth's documentation!
77
=================================================================
88

99
Contents:

docs/modules.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
web3auth
2-
========
1+
scatterauth
2+
===========
33

44
.. toctree::
55
:maxdepth: 4
66

7-
web3auth
7+
scatterauth

docs/overview.rst

+13-15
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@
22
Overview
33
========
44

5-
Django-web3-auth features 1 view for login (with JSON responses)
5+
Django-scatter-auth features 1 view for login (with JSON responses)
66
and 2 views for Signup (one with JSON responses, and the other - using Django Forms and rendered templates).
77

88
It also has 2 forms, SignupForm (rendered) and LoginForm (uses hidden inputs, used to validate data only).
99

10-
Possible configuration includes customizable address field (``SCATTERAUTH_USER_PUBKEY_FIELD``), additional fields for User model (``SCATTERAUTH_USER_SIGNUP_FIELDS``) and on/off switch for registration (``SCATTERAUTH_SIGNUP_ENABLED``).
11-
You can read more on that in the Configuration section.
10+
Possible configuration includes customizable address field (``SCATTERAUTH_USER_PUBKEY_FIELD``), additional fields for User model (``SCATTERAUTH_USER_SIGNUP_FIELDS``),on/off switch for registration (``SCATTERAUTH_SIGNUP_ENABLED``) and domain which will be used for signed message validation (``SCATTERAUTH_DOMAIN``).
11+
You can read more on that in the Settings section.
12+
You should also definitely check example app, it features most of the features needed.
1213

1314
Sign up
1415
-------
1516

1617
The signup process is as follows (signup_view example, signup_api is similar):
1718

18-
1. User heads to the signup URL (``{% url 'web3auth_signup' %}``)
19+
1. User heads to the signup URL (``{% url 'scatterauth_signup' %}``)
1920
2. The signup view is rendered with a ``SignupForm`` which includes ``SCATTERAUTH_USER_SIGNUP_FIELDS`` and ``SCATTERAUTH_USER_PUBKEY_FIELD``
2021
3. The user enters required data and clicks the submit button and the POST request fires to the same URL with ``signup_view``
2122
4. Signup view does the following:
2223
4.1. Creates an instance of a ``SignupForm``.
2324
4.2. Checks if the registration is enabled.
2425
4.3. If the registration is closed or form has errors, returns form with errors
2526
4.4 If the form is valid, saves the user without saving to DB
26-
4.5. Sets the user address from the form, saves it to DB
27-
4.6. Logins the user using ``web3auth.backend.ScatterAuthBackend``
27+
4.5. Sets the user public key from the form, saves it to DB
28+
4.6. Logins the user using ``scatterauth.backend.ScatterAuthBackend``
2829
4.7. Redirects the user to ``LOGIN_REDIRECT_URL`` or 'next' in get or post params
2930
5. The user is signed up and logged in
3031

@@ -33,14 +34,11 @@ Login
3334

3435
The login process is as follows (login_api example):
3536

36-
1. On some page of the website, there is Javascript which fires a GET request to the ``{% url 'web3auth_login_api' %}``
37-
2. The ``login_api`` view returns 32-char length login token
38-
3. Javascript on the page invites user to sign the token using web3 instance (probably Metamask)
39-
4. If the token is signed, the signature and address are sent ot he same ``login_api`` view
40-
5. The view validates signature & address against ``LoginForm`` to check that the token is signed correctly
41-
6. If the form is valid, the view tries to ``authenticate`` the user with given token,address and signature
42-
7. If the user is found, the user is signed in and the view responds with a ``redirect_url`` for Javascript to handle
43-
8. If the user is not found, the corresponding error is returned
44-
37+
1. On some page of the website, there is Javascript which gets the user signature for the website's hostname.
38+
2. The signature is sent to the login_api url (``{% url 'scatterauth_login_api' %}``) alongside the public key.
39+
3. The view validates given parameters agains ``LoginForm``
40+
4. The view validates signature with the given public key, and then tries to ``authenticate`` the user
41+
5. If the user is found, the user is signed in and the view responds with a ``redirect_url`` for Javascript to handle
42+
6. If the user is not found, the corresponding error is returned
4543

4644
The Javascript is included in the app, also you can check out example app if you are struggling with logging in the user.

docs/settings.rst

+13-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Settings
44

55
You should specify settings in your settings.py like this::
66

7-
SCATTERAUTH_USER_PUBKEY_FIELD = 'address'
7+
SCATTERAUTH_USER_PUBKEY_FIELD = 'pubkey'
88
SCATTERAUTH_USER_SIGNUP_FIELDS = ['email', 'username']
99

1010

@@ -15,23 +15,23 @@ In the above example the following User model is used:
1515
from django.contrib.auth.models import AbstractUser
1616
from django.db import models
1717
from django.utils.translation import ugettext_lazy as _
18-
from web3auth.utils import validate_eth_address
1918
2019
class User(AbstractUser):
21-
address = models.CharField(max_length=42, verbose_name=_("Ethereum wallet address"), unique=True,
22-
validators=[validate_eth_address], null=True, blank=True)
20+
pubkey = models.CharField(max_length=53, verbose_name=_("Public key"), unique=True, null=True, blank=True)
2321
2422
def __str__(self):
2523
return self.username
2624
2725
Here's a list of available settings:
2826

29-
+--------------------------------+------------+-------------------------------------------------------------------------+
30-
| Setting | Default | Description |
31-
+================================+============+=========================================================================+
32-
| SCATTERAUTH_SIGNUP_ENABLED | True | If False, new users won't be able to sign up (used in ``signup_view``) |
33-
+--------------------------------+------------+-------------------------------------------------------------------------+
34-
| SCATTERAUTH_USER_SIGNUP_FIELDS | ['email'] | Specifies field to be used in signup form for a new User model |
35-
+--------------------------------+------------+-------------------------------------------------------------------------+
36-
| SCATTERAUTH_USER_PUBKEY_FIELD | 'username' | Field on the User model, which has ethereum address to check against. |
37-
+--------------------------------+------------+-------------------------------------------------------------------------+
27+
+-----------------------------------+------------+-----------------------------------------------------------------------------------------------+
28+
| Setting | Default | Description |
29+
+===================================+============+===============================================================================================+
30+
| SCATTERAUTH_SIGNUP_ENABLED | True | If False, new users won't be able to sign up (used in ``signup_view``) |
31+
+-----------------------------------+------------+-----------------------------------------------------------------------------------------------+
32+
| SCATTERAUTH_USER_SIGNUP_FIELDS | ['email'] | Specifies field to be used in signup form for a new User model |
33+
+-----------------------------------+------------+-----------------------------------------------------------------------------------------------+
34+
| SCATTERAUTH_USER_PUBKEY_FIELD | 'username' | Field on the User model, which has public key to check against. |
35+
+-----------------------------------+------------+-----------------------------------------------------------------------------------------------+
36+
| SCATTERAUTH_DOMAIN | '' | Determines what domain to use for signature verification. If '' - request.get_host() is used |
37+
+-----------------------------------+------------+-----------------------------------------------------------------------------------------------+

scatterauth/static/scatterauth/js/scatterauth.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
1+
function jtrim(text) {
2+
var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
3+
return text == null ?
4+
"" :
5+
(text + "").replace(rtrim, "");
6+
}
7+
18
function getCookie(name) {
29
var cookieValue = null;
310
if (document.cookie && document.cookie != '') {
411
var cookies = document.cookie.split(';');
512
for (var i = 0; i < cookies.length; i++) {
6-
var cookie = jQuery.trim(cookies[i]);
13+
var cookie = jtrim(cookies[i]);
714
// Does this cookie string begin with the name we want?
815
if (cookie.substring(0, name.length + 1) == (name + '=')) {
916
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
@@ -102,7 +109,7 @@ function signupWithData(username, email, signup_url, onSignupRequestError, onSig
102109
request.send(formData);
103110
}
104111

105-
async function requestIdentity(requiredFields,signup_url, network, onIdentityReject) {
112+
async function requestIdentity(requiredFields, signup_url, network, onIdentityReject) {
106113
let identitySettings = {
107114
personal: requiredFields,
108115
};

tox.ini

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ setenv =
99
commands = coverage run --source scatterauth runtests.py
1010
deps =
1111
django-111: Django>=1.11,<1.12
12-
django-20: Django>=2.0,<2.1
12+
django-20: Django>=2.0,<2.2
1313
-r{toxinidir}/requirements_test.txt
1414
basepython =
1515
py36: python3.6
1616
py35: python3.5
1717
py34: python3.4
18-
py27: python2.7

0 commit comments

Comments
 (0)