# @bouncecode/mrlogin-sdk

> BounceCode's MrLogin SDK

Latest version **1.0.0-alpha.15** (published 2023-07-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install @bouncecode/mrlogin-sdk
pnpm add @bouncecode/mrlogin-sdk
yarn add @bouncecode/mrlogin-sdk
bun add @bouncecode/mrlogin-sdk
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.15 |
| Published | 2023-07-24 |
| First published | 2023-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 35.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | tpnet3, getbouncecode |

## Links

- npm: https://www.npmjs.com/package/@bouncecode/mrlogin-sdk
- npm.io page: https://npm.io/package/@bouncecode/mrlogin-sdk

## Dependencies (5)

- [bs58](https://npm.io/package/bs58.md) ^5.0.0
- [web3](https://npm.io/package/web3.md) ^1.8.2
- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3
- [node-fetch](https://npm.io/package/node-fetch.md) 2
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^9.0.0

## Recent versions

- 1.0.0-alpha.15 (latest) — 2023-07-24
- 1.0.0-alpha.14 — 2023-07-24
- 1.0.0-alpha.13 — 2023-04-10
- 1.0.0-alpha.12 — 2023-02-13
- 1.0.0-alpha.11 — 2023-02-13
- 1.0.0-alpha.10 — 2023-02-10
- 1.0.0-alpha.9 — 2023-02-09
- 1.0.0-alpha.8 — 2023-02-09
- 1.0.0-alpha.7 — 2023-02-09
- 1.0.0-alpha.6 — 2023-02-09
- 1.0.0-alpha.5 — 2023-02-09
- 1.0.0-alpha.4 — 2023-02-09
- 1.0.0-alpha.3 — 2023-02-09
- 1.0.0-alpha.2 — 2023-02-09
- 1.0.0-alpha.1 — 2023-02-09
- … 1 more at https://npm.io/package/@bouncecode/mrlogin-sdk/versions

## README

# Mrlogin-sdk

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

## Installation

```sh
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.

```sh
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`](#login)
- [`decodeToken`](#decodeToken)
- [`verifyToken`](#verifyToken)
- [`createDidToken`](#createDidToken)
- [`verifyDidToken`](#verifyDidToken)
- [`AccessTokenData`](#access-token-data)
- [`IDidToken`](#did-token-data)

### login

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

```sh

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)

```sh

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`](#access-token-data)

```sh

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`](#access-token-data)

```sh

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.

```sh

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`](#did-token-data)

### access-token-data

```sh
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

```sh
interface IDidTokenAdd {
    tokenId: string;
    protectedKey: string;
}
interface IDidToken {
    iat: number;
    ext: number;
    iss: string;
    sub: string;
    aud: string;
    add: IDidTokenAdd;
    nbf: number;
    tid: string;
}
```

---
_Source: https://npm.io/package/@bouncecode/mrlogin-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
