Giter Site home page Giter Site logo

mturk2422 / parse-passwordless-authentication Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brycehamrick/parse-passwordless-authentication

0.0 1.0 0.0 140 KB

An example of how to use Parse's Cloud Code to implement Passwordless Authentication

JavaScript 93.92% HTML 6.08%

parse-passwordless-authentication's Introduction

Parse Passwordless Authentication

An example of how to use Parse's Cloud Code to implement Passwordless Authentication

The token generation (including use of base58) was borrowed from @florianheinemann in his passwordless.net project.

This project uses Mailgun but could easily be modified to use another transactional email service or even something like Twilio.

Security

This will require a "Token" class and you'll want to revoke both read and write access from all roles & users. The cloud code method uses the master key and nothing else should have access.

There is some inherent risk in generating the random password on the client. I couldn't find any way around this on a first pass, but it's worth noting that it's possible that the random password could be intercepted in transit or by a malicious script in the client application. That said, this risk is also present during a conventional registration that includes a password.

Client Implementation

On the client you'll need to sign up users with a random but strong password.

function randomString(length) {
  return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1);
}

var user = new Parse.User();
user.set("username", email);
user.set("password", randomString(48));
user.set("email", email);

user.signUp(null, {
  success: function(user) {
    setCurrentUser(user);
  },
  error: function(user, error) {
    showError(error.message);
  }
});

The sign in form should just take an email address.

Parse.Cloud.run('passwordless', { email: email }, {
  success: function() {
    showSuccess("Please check your email to continue.");
  },
  error: function(error) {
    showError(error.message);
  }
});

Your token handler (the URL in the email link) needs to validate the token:

Parse.Cloud.run('passwordless', { token: token }, {
  success: function(sessionToken) {
    Parse.User.become(sessionToken).then(function (user) {
      setCurrentUser(user);
    }, function (error) {
      showError('Session Token is invalid.');
    });
  },
  error: function(error) {
    showError('Passwordless token is invalid.');
  }
});

parse-passwordless-authentication's People

Contributors

brycehamrick avatar

Watchers

 avatar

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.