2.0.2-beta.0 • Published 5 months ago

@oraichain/customauth v2.0.2-beta.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

CustomAuth Web SDKs (Previously DirectAuth)

npm version npm

Web3Multifactor is where passwordless auth meets non-custodial key infrastructure for Web3 apps and wallets. By aggregating OAuth (Google, Twitter, Discord) logins, different wallets and innovative Multi Party Computation (MPC) - Web3Auth provides a seamless login experience to every user on your application.

Introduction

This repo allows web applications to directly retrieve keys stored on the Multifactors Network. The attestation layer for the Multifactors Network is generalizable, below is an example of how to access keys via the SDK via Google.

Features

  • Typescript compatible. Includes Type definitions
  • All API's return Promises

Installation

Bundling

This module is distributed in 4 formats

  • esm build dist/customauth.esm.js in es6 format
  • commonjs build dist/customauth.cjs.js in es5 format
  • commonjs build dist/customauth-bundled.cjs.js in es5 format with problematic packages bundled (benfits non-webpack users)
  • umd build dist/customauth.umd.min.js in es5 format without polyfilling corejs minified

By default, the appropriate format is used for your specified usecase You can use a different format (if you know what you're doing) by referencing the correct file

The cjs build is not polyfilled with core-js. It is upto the user to polyfill based on the browserlist they target

Directly in Browser

CDN's serve the non-core-js polyfilled version by default. You can use a different

jsdeliver

<script src="https://cdn.jsdelivr.net/npm/@oraichain/customauth@6"></script>

unpkg

<script src="https://unpkg.com/@oraichain/customauth@6"></script>

Notes

This is a plugin that works only on the client side. So please register it as a ssr-free plugin.

Usage

For more in-depth documentation, please refer to docs here

Add @oraichain/customauth to your project:

To allow your web app to retrieve keys:

Install the package npm i @oraichain/customauth or yarn add @oraichain/customauth

CustomAuth Sdk supports two modes of login (uxMode: "popup" and uxMode: "redirect") (default: popup)

Popup Flow:

  1. Serve service worker from baseUrl where baseUrl is the one passed while instantiating CustomAuth for specific login (example http://localhost:3000/serviceworker/). If you're already using a sw, pls ensure to port over the fetch override from our service worker

  2. For browsers where service workers are not supported or if you wish to not use service workers, create and serve redirect page from baseUrl/redirect where baseUrl is the one passed while instantiating CustomAuth for specific login ( example http://localhost:3000/serviceworker/)

  3. At verifier's interface (where you obtain client id), please use baseUrl/redirect (eg: http://localhost:3000/serviceworker/redirect) as the redirect_uri where baseUrl is the one passed while instantiating CustomAuth

  4. Instantiate the package

const torus = new CustomAuth({
  baseUrl: "http://localhost:3000/serviceworker/",
  network: "testnet", // details for test net
});
await torus.init();
  1. Trigger the login with your own client id (This opens a popup of OAuth provider page)
const loginDetails = await torus.triggerLogin({
  typeOfLogin: "google",
  verifier: "YOUR VERIFER DEPLOYED BY TORUS",
  clientId: "MY CLIENT ID GOOGLE",
});

Note: If you're using redirectToOpener, modify the origin of postMessage from "http://localhost:3000" to your hosted domain in redirect.html and sw.js

Redirect flow

  1. At verifier's interface (where you obtain client id), please use baseUrl/auth (eg: http://localhost:3000/auth) as the redirect_uri where baseUrl is the one passed while instantiating CustomAuth

  2. Instantiate the package

const torus = new CustomAuth({
  baseUrl: "http://localhost:3000/serviceworker/",
  redirectPathName: "auth",
  network: "testnet", // details for test net
  uxMode: "redirect",
});
await torus.init({ skipSw: true });
  1. Trigger the login with your client id. (This redirects the user to OAuth provider page)
await torus.triggerLogin({
  typeOfLogin: "google",
  verifier: "YOUR VERIFER DEPLOYED BY TORUS",
  clientId: "MY CLIENT ID GOOGLE",
});
  1. The OAuth login completes and the OAuth provider will redirect you to baseUrl/auth with hashParams In this page, use the following code to get the login details
const torus = new CustomAuth({
  baseUrl: location.origin,
  redirectPathName: "auth",
  uxMode: "redirect",
  network: "testnet",
});
const loginDetails = await torus.getRedirectResult();
  1. Once you get the login details, you can choose to take the user anywhere else in your app

Best practices

  • Due to browser restrictions on popups, you should reduce the time taken between user interaction and the login popups being opened. This is highly browser dependent, but the best practice for this is to separate the initialization of the SDK and the user login method calls.

FAQ

  1. Question: My Redirect page is stuck in iOS Chrome

    **Answer:**

    iOS Chrome doesn't support service workers. So, you need to serve a fallback html page redirect.html Please check if redirect.html is being served correctly by navigating to baseUrl/redirect#a=123. It should show a loader

    For nginx, here is a simple server configuration
    
    ```nginx
        location ~* (/serviceworker/redirect) {
                add_header 'Access-Control-Allow-Origin' '*';
2.0.2-beta.0

5 months ago

2.0.1

5 months ago

2.0.1-beta.2

5 months ago

2.0.0

5 months ago

1.3.1-beta.0

5 months ago

1.3.0

5 months ago

1.2.19-beta.0

5 months ago

1.2.18

6 months ago

1.2.18-beta.2

6 months ago

1.2.18-beta.1

6 months ago

1.2.18-beta.0

6 months ago

1.2.17

7 months ago

1.2.17-beta.4

7 months ago

1.2.17-beta.3

7 months ago

1.2.17-beta.0

7 months ago

1.2.16

7 months ago

1.2.15

7 months ago

1.2.14

7 months ago

1.2.13

7 months ago

1.2.12

7 months ago

1.2.11

7 months ago

1.2.10

7 months ago

1.2.9

7 months ago

1.2.8

7 months ago

1.2.7

7 months ago

1.2.6

7 months ago

1.2.5

7 months ago

1.2.4

7 months ago

1.2.3

7 months ago

1.2.2

7 months ago

1.2.1

8 months ago

1.2.0

8 months ago

1.1.5

8 months ago

1.1.4

9 months ago

1.1.3

9 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.3

9 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago