1.0.0-alpha.15 • Published 10 months ago

@bouncecode/mrlogin-sdk v1.0.0-alpha.15

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

Mrlogin-sdk

This SDK helps developers get started with the SSO login service in React.js provided by Bouncecode.

Installation

npm install @bouncecode/mrlogin-sdk
// or
yarn add @bouncecode/mrlogin-sdk

Set up

The entry point to the JavaScript SDK is a Mrlogin instance that will give you access to its API.

import Mrlogin from "@bouncecode/mrlogin-sdk";

// MrloginOptions { projectId, endpoint, port }  default endpoint = https://mrlogin.io
// projectId :
// 1. go to https://mrlogin.io
// 2. sign up
// 3. Check the project id in url . https://mrlogin.io/manage/{your-project-id}/users/list/

// project Id is required
const projectId = 'your project id';

// endpoint is optional , default : https://mrlogin.io
const endpoint = 'https://mrlogin.io';

// port is optional.
const port = undefined;

const mrlogin = new Mrlogin({ projectId, endpoint, port  }: MrloginOptions);

Usage

login

The login method navigates to the project login page and redirects to the redirect URI containing the login result as the url parameter.

const mrlogin = new Mrlogin({ 'your-project-id', 'https://mrlogin.io' });

mrlogin.login('your-redirect-uri');
// login result : https://your-redirecrt-uri/?access_token='user-access-token'&refresh_token='user-refresh-token'

Get login result (react.js)

import Mrlogin from "@bouncecode/mrlogin-sdk";
import { useEffect, useState } from "react";

const [loggedData, setLoggedData] = useState();

useEffect(() => {
    let parsedUrl = new URL(window.location.href);
    const accessToken = parsedUrl.searchParams.get("access_token");
    const refreshToken = parsedUrl.searchParams.get("refresh_token");

    if (accessToken || refreshToken) {
      setLoggedData({
        accessToken: jwt.decode(accessToken),
        refreshToken: refreshToken,
      });
    }
  }, []);

decodeToken

The decode Token method decodes the access token issued after completing login and returns the data included in the access_token. an JwtPayload & AccessTokenData

const mrlogin = new Mrlogin({ 'your-project-id', 'https://mrlogin.io' });

const token = 'user-access-token';

const data = mrlogin.decodeToken(token);

verifyToken

The 'verify Token' method returns the data included in access_token by verifying and decrypting the access token issued after login on the server. an AccessTokenData

const mrlogin = new Mrlogin({ 'your-project-id', 'https://mrlogin.io' });

const token = 'user-access-token';

const data = mrlogin.verifyToken(token);

createDidToken

The 'createDidToken' method issues and returns a did_Token containing a decentralized ID (DID) from the server through an access_token.

The DID token is encoded as a Base64 JSON string tuple representing proof, claim:

proof: A digital signature that proves the validity of the given claim.

claim: Unsigned data the user asserts. This should equal the proof after Elliptic Curve recovery.

const mrlogin = new Mrlogin({ 'your-project-id', 'https://mrlogin.io' });

const token = 'user-access-token';

const didTokenSolana = await mrlogin.createDidToken("solana", token);

const didTokenEther = await mrlogin.createDidToken("ether", token);

verifyDidToken

The 'verifyDidToken' method verifies and decrypts the did token and returns the data contained in did_token. an IDidToken

access-token-data

interface AccessTokenData {
    customUserData?: any;
    email: string;
    multiFactor?: string;
    oauthToken?: any;
    passwordUpdatedDate?: Date;
    phoneNumber?: string;
    projectAdmin?: any;
    projectId: string;
    protectedBackupKey?: string;
    protectedShareKey?: string;
    provider: string;
    reported?: Date;
    tokenId?: string;
    userId: string;
    verifiedAt?: Date;
    verifiedEmail?: boolean;
    verifiedEmailAt?: Date;
    verifiedMobileIdentity?: boolean;
    verifiedMobileIdentityAt?: Date;
    verifyInterest?: Date;
    verifySMS?: boolean;
    verifyTerm?: Date;
}

did-token-data

interface IDidTokenAdd {
    tokenId: string;
    protectedKey: string;
}
interface IDidToken {
    iat: number;
    ext: number;
    iss: string;
    sub: string;
    aud: string;
    add: IDidTokenAdd;
    nbf: number;
    tid: string;
}
1.0.0-alpha.15

10 months ago

1.0.0-alpha.14

10 months ago

1.0.0-alpha.13

1 year ago

1.0.0-alpha.12

1 year ago

1.0.0-alpha.11

1 year ago

1.0.0-alpha.10

1 year ago

1.0.0-alpha.9

1 year ago

1.0.0-alpha.8

1 year ago

1.0.0-alpha.7

1 year ago

1.0.0-alpha.6

1 year ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.4

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

1.0.0

1 year ago