3.0.1 • Published 1 year ago

autharmor-node-sdk v3.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
1 year ago

AuthArmor Node.js SDK

ℹ For Express.js Users

We recommend you to use the AuthArmor Express SDK in case you would like to go for a simple and easy-to-use solution for setting up AuthArmor Authentication.

If you'd like a more advanced and flexible interface for using the AuthArmor API, you can proceed with setting up the AuthArmor Node SDK.

🏁 Installation

You can integrate the AuthArmor SDK into your backend by installing and importing our NPM package:

# Via NPM
npm i -s autharmor-node-sdk

# Via Yarn
yarn add autharmor-node-sdk

🧭 Usage

🚀 Initializing the SDK

In order to initialize the SDK, you'll have to create a new instance of the AuthArmor Node.js SDK with your Client ID and Client Secret specified in it.

const AuthArmor = new AuthArmorSDK({
  clientId: "1234-1234-1234-1234",
  clientSecret: "123456789"
}); // specify your client credentials

How Does it work?

For information regarding how AuthArmor works and its concepts, please visit the Documentation site

🌏 HTTP Routes and Schema

Default Client-side SDK Routes

We recommend you specify the following HTTP routes in your backend so it works immediately with the AuthArmor Client SDK. You can always change the routes in the Client-side SDK as well if you need to.

NameRoute
Create Invite (Register)POST /auth/autharmor/invite
Confirm InvitePOST /auth/autharmor/invite/confirm
AuthenticatePOST /auth/autharmor/auth
Get user authentication statusGET /auth/autharmor/me
LogoutGET /auth/autharmor/logout

Required HTTP request body schema

All of your AuthArmor HTTP routes should match the ones specified below to work with the Client SDK.

Create Invite

Field NameTypeDescriptionRequired
nicknamestringThe user's username, nicknames should be unique for each user
reference_idstringAn optional identifier for the new user in the DB
reset_and_reinvitebooleanSpecifies whether this invite should overwrite any existing users

Confirm Invite

Field NameTypeDescriptionRequired
nicknamestringThe user's username, nicknames should be unique for each user

Authenticate

Field NameTypeDescriptionRequired
nicknamestringThe user's username, nicknames should be unique for each user

🧲 Invites

Generating a new invite

You can easily generate invites to your app and register new users with Auth Armor by doing the following:

// Initialize the SDK
const AuthArmor = new AuthArmorSDK({
  clientId: "1234-1234-1234-1234",
  clientSecret: "123456789"
});

// Generate a new invite
const invite = await AuthArmor.invite({
  nickname: "", // Specify the invite's nickname
  referenceId: "" // Specify a reference ID for the invite
});

console.log(invite);
/**
 * Returns:
 * {
 *   "auth_profile_id": "`string`",
 *   "invite_code": "`string`",
 *   "date_expires": "ISODate `string`",
 *   "invite_type": "`string`",
 *   "aa_sig": "`string`"
 * }
 */

Handling invites

Once an invite is generated, you'll need to save its info somewhere in your database along with the user's username so once the user tries to confirm the invite, you can retrieve the invite's info from the database, create an invite confirmation request and if the invite confirmation request succeeds, you can create a new user record and save it in your database.

🔏 Authentication

Initializing an authentication request

In order to initialize a login request for authenticating users to your site, you can simply call the authenticate() function with the auth request's config (Nickname, Action name, Short Message) and an authentication request will be sent to your user's phone. Once the user responds to the auth request, the authenticate() function's Promise resolves

try {
  console.log("Authenticating user...");
  await AuthArmor.authenticate({
    nickname: "<username>",
    action_name: "Lorem ipsum",
    short_msg: "Lorem ipsum dolor sit amet."
  });
  console.log("User authenticated!");
} catch (err) {
  console.error("The request was declined or has timed out!", err);
}
3.0.1

1 year ago

3.0.0-beta.25

2 years ago

3.0.0-beta.26

2 years ago

3.0.0-beta.27

2 years ago

3.0.0

2 years ago

3.0.0-beta.20

2 years ago

3.0.0-beta.21

2 years ago

3.0.0-beta.22

2 years ago

3.0.0-beta.23

2 years ago

3.0.0-beta.24

2 years ago

3.0.0-beta.19

2 years ago

3.0.0-beta.13

2 years ago

3.0.0-beta.14

2 years ago

3.0.0-beta.15

2 years ago

3.0.0-beta.16

2 years ago

3.0.0-beta.17

2 years ago

3.0.0-beta.18

2 years ago

3.0.0-beta.10

2 years ago

3.0.0-beta.11

2 years ago

3.0.0-beta.12

2 years ago

3.0.0-beta.1

2 years ago

3.0.0-beta.3

2 years ago

3.0.0-beta.2

2 years ago

3.0.0-beta.5

2 years ago

3.0.0-beta.4

2 years ago

3.0.0-beta.7

2 years ago

3.0.0-beta.6

2 years ago

3.0.0-beta.9

2 years ago

3.0.0-beta.8

2 years ago

2.3.0

2 years ago

2.3.1

2 years ago

2.2.1

2 years ago

2.2.0

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.2.2

2 years ago

2.1.3

2 years ago

2.1.0

2 years ago

2.0.0

2 years ago

2.0.0-alpha.31

3 years ago

2.0.0-alpha.30

3 years ago

2.0.0-alpha.29

3 years ago

2.0.0-alpha.28

3 years ago

2.0.0-alpha.27

3 years ago

2.0.0-alpha.26

3 years ago

2.0.0-alpha.25

3 years ago

2.0.0-alpha.24

3 years ago

2.0.0-alpha.19

3 years ago

2.0.0-alpha.18

3 years ago

2.0.0-alpha.22

3 years ago

2.0.0-alpha.21

3 years ago

2.0.0-alpha.20

3 years ago

2.0.0-alpha.23

3 years ago

2.0.0-alpha.17

3 years ago

2.0.0-alpha.16

3 years ago

2.0.0-alpha.15

3 years ago

2.0.0-alpha.7

3 years ago

2.0.0-alpha.8

3 years ago

2.0.0-alpha.9

3 years ago

2.0.0-alpha.11

3 years ago

2.0.0-alpha.10

3 years ago

2.0.0-alpha.5

3 years ago

2.0.0-alpha.6

3 years ago

2.0.0-alpha.14

3 years ago

2.0.0-alpha.13

3 years ago

2.0.0-alpha.12

3 years ago

2.0.0-alpha.3

3 years ago

2.0.0-alpha.4

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0-alpha.1

3 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago