just-login-core
Handles the authentication at the database level for other just login modules
Last updated 5 years ago by artskydj .
VOL · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install just-login-core 
SYNC missed versions from official npm registry.

just-login-core

Build Status

Handles tokens for just-login.

Example

var JustLoginCore = require('just-login-core')
var db = require('level-mem')()
var core = JustLoginCore(db)

API

var Core = require('just-login-core')

var core = JustLoginCore(db[, options])

  • db is expecting a levelup database.
  • options is an object that holds the (gasp) options!
    • tokenGenerator is expecting a function that returns an unique string each time it is called. This is used for token generation. Defaults to a UUID generator.
    • tokenTtl is a number in milliseconds of a token's Time To Live (TTL). Defaults to 5 minutes.
    • tokenTtlCheckIntervalMs is a number in milliseconds of the ttl's check interval. (See tiny-level-ttl, checkInterval.) Defaults to 10 seconds.
  • Returns core.

core

It emits some events and has a few methods:

core.beginAuthentication(sessionId, contactAddress[, cb])

Starts the authentication process by emitting the 'authentication initiated' event with a token and the contact address.

Something else must listen for the event, and send a message to the user. See core events for more information.

  • sessionId is a string of the session id that is trying to get authenticated.
  • contactAddress is string of the user's contact info, (usually an email address).
  • cb is a function with the following arguments:
    • err is an Error object or null.
    • authReqInfo is an object with the authentication request information. The object is identical to the object emitted in the event, with the following properties:
      • contactAddress is a string with the contact address.
      • token is a string of the token.
  • Emits core.on('authentication initiated', function (authReqInfo) { ... })
core.beginAuthentication('session id', 'fake@example.com', function (err, authReqInfo) {
	if (!err) {
		console.log(authReqInfo.token) //logs the token
		console.log(authReqInfo.contactAddress) //logs: "fake@example.com"
	}
})

core.authenticate(token[, cb])

Authenticates the token, and calls back with the session id and contact address associated with that token. Then the token and it's associated data is deleted. A token can only be authenticated once.

  • token is a string of the token that is trying to get authenticated.
  • cb is a function with the following arguments:
    • err is an Error object or null.
    • credentials is null is the user is not authenticated, and is an object if they are authenticated:
      • contactAddress is a string of their contact address.
      • sessionId is a string of their session id.
  • Emits core.on('authenticated', function (credentials) { ... })
core.authenticate('the token', function(err, credentials) {
	if (!err) {
		console.log(credentials.contactAddress + ' is now logged in! Congratulations!')
	} else {
		console.log('Sorry, for some reason you are not logged in.')
	}
})

core events

authentication initiated

Emitted when beginAuthentication() is called. (Which should be when the user clicks the "login" button.)

core.on('authentication initiated', function (authReqInfo) {
	console.log(authReqInfo.contactAddress)
	console.log(authReqInfo.token)
})

(You can use just-login-emailer to catch this event.)

authenticated

Emitted when core.authenticate() is successful.

core.on('authenticated', function (credentials) {
	console.log(credentials.contactAddress)
	console.log(credentials.sessionId)
})

Install

Install with npm:

npm install just-login-core

License

VOL

Current Tags

  • 2.0.1                                ...           latest (5 years ago)

28 Versions

  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.3.2                                ...           6 years ago
  • 1.3.1                                ...           6 years ago
  • 1.3.0                                ...           6 years ago
  • 1.2.7                                ...           6 years ago
  • 1.2.6                                ...           6 years ago
  • 1.2.5                                ...           6 years ago
  • 1.2.4                                ...           6 years ago
  • 1.2.3                                ...           6 years ago
  • 1.2.2                                ...           6 years ago
  • 1.2.1                                ...           6 years ago
  • 1.2.0                                ...           6 years ago
  • 1.1.4                                ...           6 years ago
  • 1.1.3                                ...           6 years ago
  • 1.1.2                                ...           6 years ago
  • 1.1.1                                ...           6 years ago
  • 1.1.0                                ...           6 years ago
  • 1.0.8                                ...           6 years ago
  • 1.0.7                                ...           6 years ago
  • 1.0.6                                ...           6 years ago
  • 1.0.5                                ...           6 years ago
  • 1.0.4                                ...           6 years ago
  • 1.0.3                                ...           6 years ago
  • 1.0.2                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (2)

Copyright 2014 - 2016 © taobao.org |