Giter Club home page Giter Club logo

django-scatter-auth's Introduction

django-scatter-auth

image

image

image

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.

image

Documentation

The full documentation is at https://django-scatter-auth.readthedocs.io.

Example project

https://github.com/Bearle/django-scatter-auth/tree/master/example

You can check out our example project by cloning the repo and heading into example/ directory. There is a README file for you to check, also.

Features

  • Scatter API login, signup
  • Scatter Django forms for signup, login
  • Checks signature (validation)
  • Uses hostname signing as proof of private key posession
  • Easy to set up and use (just one click)
  • Custom auth backend
  • VERY customizable - uses Django settings, allows for custom User model
  • Vanilla Javascript helpers included

Quickstart

Install django-scatter-auth with pip:

pip install django-scatter-auth

Add it to your `INSTALLED_APPS`:

INSTALLED_APPS = (
    ...
    'scatterauth.apps.scatterauthConfig',
    ...
)

Set 'scatterauth.backend.ScatterAuthBackend' as your authentication backend:

AUTHENTICATION_BACKENDS = [
'django.contrib.auth.backends.ModelBackend',
'scatterauth.backend.ScatterAuthBackend'
]

Set your User model's field to use as public key storage:

SCATTERAUTH_USER_PUBKEY_FIELD = 'username'

And if you have some other fields you want to be in the SignupForm, add them too:

SCATTERAUTH_USER_SIGNUP_FIELDS = ['email',]

Add django-scatter-auth's URL patterns:

from scatterauth import urls as scatterauth_urls


urlpatterns = [
    ...
    url(r'^', include(scatterauth_urls)),
    ...
]

Add some javascript to handle login:

<script src="{% static 'scatterauth/js/scatterauth.js' %}"></script>
var login_url = '{% url 'scatterauth_login_api' %}';
document.addEventListener('scatterLoaded', scatterExtension => {
  console.log('scatter loaded');
  if (scatter.identity) {
    console.log("Identity found");
    loginWithAuthenticate(login_url,console.log,console.log,console.log,console.log, function (resp) {
      window.location.replace(resp.redirect_url);
    });
  } else {
    console.log('identity not found, have to signup');
  }
});

You can access signup using {% url 'scatterauth_signup' %} and API signup using {% url 'scatterauth_signup_api' %}.

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

Important details and FAQ

  1. If you set a custom public key field (SCATTERAUTH_USER_PUBKEY_FIELD), it MUST be unique (unique=True).

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

  1. How do i deal with user passwords or Password is not set

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. Or, even better, sends them a 'restore password' link. 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.

  1. Why don't i have to sign a message? It's needed in django-web3-auth, how this app is secure?

This app uses scatter's authenticate function to handle message signing - hostname being the signed message. This means that the user & the client share knowledge of the original message and the server can verify client's possession of the private key corresponding to the public key.

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Credits

Tools used in rendering this package:

django-scatter-auth's People

Contributors

delneg avatar zagrebelin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

django-scatter-auth's Issues

scatter not installed

  • Django-Scatter-Auth version: same
  • Django version: same
  • Python version: 3.5
  • Operating System: Ubuntu 1602

Description

Hi, sir. I run your example. and the website show “scatter not installed”.
How can i install scatter in ubuntu?
Just run linux-scatter-12.1.1-x86_64.AppImage berfore i run "python manage.py runserver"?
Thanks for your help.

What I Did

root@ubuntu:/home/neko/Desktop/django-scatter-auth-master/example# python3 ./manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
April 22, 2021 - 06:48:45
Django version 2.1.2, using settings 'example.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[22/Apr/2021 06:48:56] "GET / HTTP/1.1" 200 3809
Not Found: /favicon.ico
[22/Apr/2021 06:50:38] "GET /favicon.ico HTTP/1.1" 404 2881
[22/Apr/2021 06:51:03] "GET / HTTP/1.1" 200 3809
Not Found: /favicon.ico
[22/Apr/2021 06:52:26] "GET /favicon.ico HTTP/1.1" 404 2881
[22/Apr/2021 06:52:31] "GET /auto_login/ HTTP/1.1" 200 3965

Can it support desktop versions?

thank you for the example.
i use it on chrome app is work.
but scatter desktop(10.1.0) did not work.
how do i change it to apply to scatter desktop?

English is not my native language; please excuse typing errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.