squarelink-auth

Squarelink Auth Javascript SDK


Keywords
Node.js, Squarelink, Authentication, Blockchain, Dapp, Decentralized, auth-api, private-key, private-key-infrastructure
License
MIT
Install
npm install squarelink-auth@0.4.12

Documentation

Squarelink Auth Library for Node.js

Installation

$ npm install squarelink-auth

Usage

var squarelink = require('squarelink-auth')

User Registration

Request an Account

squarelink.Register.requestAccount({
  client_id: "xxx",
  username: "user's email",
  response_token: "ReCaptcha response"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "account exists | account issued",
  salt: "xxx",
  id_token: "xxx", //save this
  expires: DateTime
}

Create/complete the Account

squarelink.Register.createAccount({
  client_id: "xxx",
  id_token: "xxx",
  username: "user's email",
  password: "user's password",
  salt: "xxx",
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "token expired | verification sent | account created",
  access_token: "xxx",
  expires: DateTime,
  permissions: ["recovery_setup", "2fa_setup"],
  public_key: "xxx",
  private_key: "xxx"
}

Verify the Account's email

squarelink.Register.verifyAccount({
  client_id: "xxx",
  id_token: "xxx",
  pub_key: "xxx",
  verification_token: "xxx",
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
	success: true | false,
	message: "token expired | account verified",
	access_token: "xxx", //if same device/IP used
	expires: DateTime,
  salt: "xxx", //if new device used
  challenge: "xxx", //if new device
	permissions: [recovery_setup, 2fa_setup]
}

2-Factor Setup

Request an OTP Seed URI for an Authenticator App

squarelink.SecondFactorSetup.requestSeed({
  pub_key: "xxx",
  access_token: "xxx",
  client_id: "xxx"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "token_expired | 2fa_exists",
  seed_url: "otpauth://totp/{{application name}}/secret={{secret}}&issuer={{client_id}}"
}

Setup SMS verification

squarelink.SecondFactorSetup.sms({
  client_id: "xxx",
  access_token: "xxx",
  pub_key: "xxx",
  phone: 1234567890, //10 digits, no dashes,
  country: 1 //for U.S.
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "invalid phone | already setup | verification sent"
}

Verify One-time Password to Complete Setup

squarelink.SecondFactorSetup.verify({
  client_id: "xxx",
  access_token: "xxx",
  pub_key: "xxx",
  code: 123456
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "invalid code | expired code | setup complete"
}

Login

Request Access for user

squarelink.Login.requestAccess({
  username: "user's email",
  client_id: "xxx"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
	message: "account not verified | account not found | verification code sent"
	account_settings: {
		2fa: true | false,
	},
	id_token: "xxx",
	expires: DateTime
}

Verify User's 2FA code/OTP

squarelink.Login.verify2fa({
  client_id: "xxx",
  id_token: "xxx",
  code: 123456
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
	message: "token invalid | code invalid",
	salt: "xxx",
	challenge: "xxx" //save this
}

Verify ReCaptcha Response

squarelink.Login.verifyRecaptcha({
  client_id: "xxx",
  id_token: "xxx",
  response_token: "ReCaptcha response"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
	message: "invalid response_token | token expired",
	salt: "xxx",
	challenge: "xxx"
}

Solve the Challenge and Authenticate user

squarelink.Login.solveChallenge({
  username: "user's email",
  password: "xxx",
  salt: "xxx",
  challenge: "xxx",
  id_token: "xxx",
  client_id: "xxx"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "invalid password | token expired" //if error
  access_token: "xxx",
  permissions: [...],
  private_key: "xxx",
  public_key: "xxx"
}

Account Recovery Setup

Get a list of recovery questions

squarelink.RecoverySetup.listQuestions({
  client_id: "xxx",
  access_token: "xxx"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: "access_token expired || ...",
  questions: [
    'option1',
    'option2',
    ...
  ]
}

Setup Recovery via Recovery Questions

squarelink.RecoverySetup.recoveryQuestionsSetup({
  questions: {
    0: "question1",
    1: "question2",
    2: "question3"
  },
  answers: {
    0: "answer1",
    1: "answer2",
    2: "answer3"
  },
  salt: "xxx",
  access_token: "xxx",
  client_id: "xxx",
  pub_key: "xxx",
  private_key: "xxx"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: 'recovery setup || error setting up recovery'
}

Recovery and Reset a User's account

Get the user's recovery questions

squarelink.Recovery.getQuestions({
  id_token: "xxx",
  client_id: "xxx"
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true | false,
  message: 'solve challenge',
  questions:
   { '0': 'question1',
     '1': 'question2',
     '2': 'question3' },
  challenge: 'xxx'
}

Solve the challenge to verify correct answers

squarelink.Recovery.solveChallenge({
  answers: {
    0: "answer1",
    1: "answer2",
    2: "answer3"
  },
  salt: "xxx",
  challenge: "xxx",
  id_token: "xxx",
  client_id: "xxx",
}).then(function(response) {
  //your code
}).catch(function(err) {
  //error messages
})

Response:

{
  success: true || false,
  message: 'challenge solved, continue recovery || one or more answers incorrect',
  recovery_seed: 'xxx',
  salt: 'xxx',
  recovery_key: 'xxx'
}

Reset the User's account with a new password

squarelink.Recovery.reset({
  recovery_key: "xxx",
  recovery_seed: "xxx",
  username: "original email",
  password: "xxx", //new password
  salt: "xxx", //new salt
  answers: {
    0: "answer1",
    1: "answer2",
    2: "answer3"
  },
  id_token: "xxx",
  client_id: "xxx"
}).then(function(response) {
  // your code
}).catch(function(err) {
  // error messages
})

Response:

{
  success: true || false,
  message: 'account reset',
  access_token: 'xxx',
  private_key: 'xxx',
  public_key: 'xxx',
  old_key: 'xxx'
}