From d29c57250292f4410fa26da2220e5deb47a1b8b2 Mon Sep 17 00:00:00 2001 From: chaitanyapotti Date: Wed, 10 Nov 2021 16:27:58 +0800 Subject: [PATCH] Rename package --- .gitignore | 2 +- .npmignore | 2 +- README.md | 65 ++++++++++--------- examples/angular-app/README.md | 6 +- examples/angular-app/angular.json | 2 +- examples/angular-app/package-lock.json | 4 +- examples/angular-app/package.json | 2 +- .../src/app/home/home.component.ts | 2 +- .../popup-mode-login.component.ts | 2 +- .../redirect-mode-auth.component.ts | 2 +- .../redirect-mode-login.component.ts | 2 +- examples/firebase-example/README.md | 18 ++--- examples/firebase-example/public/app.js | 2 +- examples/firebase-example/public/index.html | 6 +- examples/nextjs-app/README.md | 4 +- examples/nextjs-app/package-lock.json | 4 +- examples/nextjs-app/package.json | 2 +- examples/nextjs-app/pages/auth.tsx | 2 +- examples/nextjs-app/pages/index.tsx | 2 +- examples/nextjs-app/pages/popupMode/login.tsx | 2 +- .../nextjs-app/pages/redirectMode/login.tsx | 2 +- examples/react-app/README.md | 5 +- examples/react-app/package-lock.json | 4 +- examples/react-app/package.json | 2 +- examples/react-app/src/App.tsx | 2 +- examples/react-app/src/popupMode/login.tsx | 2 +- examples/react-app/src/redirectMode/auth.tsx | 2 +- examples/react-app/src/redirectMode/login.tsx | 2 +- examples/starkware-react-example/README.md | 5 +- .../starkware-react-example/package-lock.json | 4 +- examples/starkware-react-example/package.json | 2 +- examples/starkware-react-example/src/App.tsx | 2 +- .../src/popupMode/login.tsx | 2 +- .../src/redirectMode/auth.tsx | 2 +- .../src/redirectMode/login.tsx | 2 +- examples/vue-app/README.md | 9 ++- examples/vue-app/package-lock.json | 4 +- examples/vue-app/package.json | 2 +- examples/vue-app/src/HomePage.vue | 2 +- .../vue-app/src/views/PopupMode/Login.vue | 2 +- .../vue-app/src/views/RedirectMode/Auth.vue | 2 +- .../vue-app/src/views/RedirectMode/Login.vue | 2 +- package-lock.json | 2 +- package.json | 21 +++--- src/handlers/interfaces.ts | 6 +- src/login.ts | 8 +-- src/utils/loglevel.ts | 2 +- test/index.html | 4 +- torus.config.js | 1 - 49 files changed, 127 insertions(+), 113 deletions(-) diff --git a/.gitignore b/.gitignore index 9491222c..d88c89b8 100644 --- a/.gitignore +++ b/.gitignore @@ -103,7 +103,7 @@ dist # TernJS port file .tern-port -toruslabs-torus-direct-web-sdk-* +toruslabs-customauth-* bundle.min.js types2/ .DS_Store \ No newline at end of file diff --git a/.npmignore b/.npmignore index 15e001ea..e52d0828 100644 --- a/.npmignore +++ b/.npmignore @@ -101,7 +101,7 @@ typings/ examples/ -toruslabs-torus-direct-web-sdk-* +toruslabs-customauth-* ssl/ src/ scripts/ diff --git a/README.md b/README.md index decd215a..f872b60f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # CustomAuth Web SDKs (Previously DirectAuth) -[![npm version](https://badge.fury.io/js/%40toruslabs%2Ftorus-direct-web-sdk.svg)](https://badge.fury.io/js/%40toruslabs%2Ftorus-direct-web-sdk) -![npm](https://img.shields.io/npm/dw/@toruslabs/torus-direct-web-sdk) +[![npm version](https://badge.fury.io/js/%40toruslabs%2Fcustomauth.svg)](https://badge.fury.io/js/%40toruslabs%2Fcustomauth) +![npm](https://img.shields.io/npm/dw/@toruslabs/customauth) ## Introduction @@ -18,10 +18,10 @@ This repo allows web applications to directly retrieve keys stored on the Torus This module is distributed in 4 formats -- `esm` build `dist/directWebSdk.esm.js` in es6 format -- `commonjs` build `dist/directWebSdk.cjs.js` in es5 format -- `commonjs` build `dist/directWebSdk-bundled.cjs.js` in es5 format with problematic packages bundled (benfits non-webpack users) -- `umd` build `dist/directWebSdk.umd.min.js` in es5 format without polyfilling corejs minified +- `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 @@ -36,13 +36,13 @@ CDN's serve the non-core-js polyfilled version by default. You can use a differe jsdeliver ```js - + ``` unpkg ```js - + ``` ### Tips for NUXT @@ -53,29 +53,29 @@ This is a plugin that works [only on the client side](https://nuxtjs.org/guide/p For more in-depth documentation, please refer to docs [here](https://docs.tor.us/customauth/get-started) -Add [`@toruslabs/torus-direct-web-sdk`](https://www.npmjs.com/package/@toruslabs/torus-direct-web-sdk) to your project: +Add [`@toruslabs/customauth`](https://www.npmjs.com/package/@toruslabs/customauth) to your project: To allow your web app to retrieve keys: Install the package - `npm i @toruslabs/torus-direct-web-sdk` - or - `yarn add @toruslabs/torus-direct-web-sdk` +`npm i @toruslabs/customauth` +or +`yarn add @toruslabs/customauth` -Direct Web Sdk supports two modes of login (`uxMode: "popup"` and `uxMode: "redirect"`) (default: `popup`) +CustomAuth Sdk supports two modes of login (`uxMode: "popup"` and `uxMode: "redirect"`) (default: `popup`) #### Popup Flow: -1. Serve [service worker](serviceworker/sw.js) from `baseUrl` where baseUrl is the one passed while instantiating `DirectWebSdk` 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](serviceworker/sw.js) +1. Serve [service worker](serviceworker/sw.js) 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](serviceworker/sw.js) -2. For browsers where service workers are not supported or if you wish to not use service workers, create and serve [redirect page](serviceworker/redirect.html) from `baseUrl/redirect` where baseUrl is the one passed while instantiating `DirectWebSdk` for specific login ( example http://localhost:3000/serviceworker/) +2. For browsers where service workers are not supported or if you wish to not use service workers, create and serve [redirect page](serviceworker/redirect.html) 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 `DirectWebSdk` +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 - + ```js -const torus = new DirectWebSdk({ +const torus = new CustomAuth({ baseUrl: "http://localhost:3000/serviceworker/", network: "testnet", // details for test net }); @@ -96,18 +96,18 @@ Note: If you're using `redirectToOpener`, modify the origin of postMessage from #### 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 `DirectWebSdk` +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 - + ```js -const torus = new DirectWebSdk({ +const torus = new CustomAuth({ baseUrl: "http://localhost:3000/serviceworker/", redirectPathName: "auth", network: "testnet", // details for test net - uxMode: "redirect" + uxMode: "redirect", }); -await torusdirectsdk.init({ skipSw: true }); +await torus.init({ skipSw: true }); ``` 3. Trigger the login with your client id. (This redirects the user to OAuth provider page) @@ -120,24 +120,25 @@ await torus.triggerLogin({ }); ``` -4. The OAuth login completes and the OAuth provider will redirect you to `baseUrl/auth` with hashParams +4. 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 ```js -const torusdirectsdk = new DirectWebSdk({ +const torus = new CustomAuth({ baseUrl: location.origin, redirectPathName: "auth", uxMode: "redirect", - network: "testnet" + network: "testnet", }); -const loginDetails = await torusdirectsdk.getRedirectResult(); +const loginDetails = await torus.getRedirectResult(); ``` 5. Once you get the login details, you can choose to take the user anywhere else in your app - + ## Examples Please refer to examples + - [vue](examples/vue-app/src/App.vue) for popup flow - [react](examples/react-app/src/App.js) for popup flow - [nextjs](examples/nextjs-app/src/_app.js) for redirect flow @@ -145,7 +146,8 @@ Please refer to examples - [vue](examples/vue-app-redirect-flow/src/App.vue) for redirect flow - [gatsby](https://github.com/jamespfarrell/gatsby-torus-direct) for configuration -Hosted Example for testing +Hosted Example for testing + - [Popup Flow](https://vue-direct.tor.us/) - [Redirect Flow](https://vue-redirect.tor.us/) @@ -224,7 +226,7 @@ await axios.post("https://discordapp.com/api/oauth2/token/revoke", formData, { **Question:** How to initialise web3 with private key (returned after login) ? **Answer:** -One can use privateKeyToAccount method to initialise web3 with a privatekey. If you are supplying a hexadecimal number, it must have 0x prefix in order to be in line with other Ethereum libraries. +One can use privateKeyToAccount method to initialise web3 with a privatekey. If you are supplying a hexadecimal number, it must have 0x prefix in order to be in line with other Ethereum libraries. ```js web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY); @@ -236,4 +238,5 @@ web3.eth.accounts.privateKeyToAccount(PRIVATE_KEY); - Node 12+ ### Note -If you are using the redirectToOpener option, you *must* update your redirect.html to [allow whitelisted URIs](serviceworker/redirect.html#L222) + +If you are using the redirectToOpener option, you _must_ update your redirect.html to [allow whitelisted URIs](serviceworker/redirect.html#L222) diff --git a/examples/angular-app/README.md b/examples/angular-app/README.md index 718f87b4..06c5ecdc 100644 --- a/examples/angular-app/README.md +++ b/examples/angular-app/README.md @@ -1,12 +1,14 @@ -# Direct Web SDK - Angular App Notes +# CustomAuth SDK - Angular App Notes -For general instructions [click here](https://github.com/torusresearch/torus-direct-web-sdk) +For general instructions [click here](https://github.com/torusresearch/customauth) How to run example 1. Build the outer project using `npm pack` 2. Install the built tgz file in this folder using `npm i ../../toruslabs-.......` + ## Running the App locally + Requires [http-server](https://github.com/http-party/http-server) installed globally. Add these scripts on package.json. Some login providers require `https` connection diff --git a/examples/angular-app/angular.json b/examples/angular-app/angular.json index de6c2a48..ca71b0c6 100644 --- a/examples/angular-app/angular.json +++ b/examples/angular-app/angular.json @@ -21,7 +21,7 @@ "builder": "@angular-devkit/build-angular:browser", "options": { "allowedCommonJsDependencies": [ - "@toruslabs/torus-direct-web-sdk", + "@toruslabs/customauth", "jwt-decode", "@toruslabs/fetch-node-details", "web3-utils", diff --git a/examples/angular-app/package-lock.json b/examples/angular-app/package-lock.json index b4812c5b..c0e17275 100644 --- a/examples/angular-app/package-lock.json +++ b/examples/angular-app/package-lock.json @@ -2611,9 +2611,9 @@ "deepmerge": "^4.2.2" } }, - "@toruslabs/torus-direct-web-sdk": { + "@toruslabs/customauth": { "version": "4.14.1", - "resolved": "https://registry.npmjs.org/@toruslabs/torus-direct-web-sdk/-/torus-direct-web-sdk-4.14.1.tgz", + "resolved": "https://registry.npmjs.org/@toruslabs/customauth/-/customauth-4.14.1.tgz", "integrity": "sha512-Vie3MUecEj/P/xDkoSN1Y8mUWOa9NLyuURHbOQi6rDbRtArGQ2tf6jyPyP2vofAeUD8x0rRE+b1l7I4sOJDOFQ==", "requires": { "@chaitanyapotti/random-id": "^1.0.3", diff --git a/examples/angular-app/package.json b/examples/angular-app/package.json index ead31828..c73c06f0 100644 --- a/examples/angular-app/package.json +++ b/examples/angular-app/package.json @@ -25,7 +25,7 @@ "stream-browserify": "^3.0.0", "tslib": "^2.2.0", "zone.js": "~0.11.4", - "@toruslabs/torus-direct-web-sdk": "file:../../toruslabs-torus-direct-web-sdk-4.14.3.tgz" + "@toruslabs/customauth": "file:../../toruslabs-customauth-4.14.3.tgz" }, "devDependencies": { "@angular-builders/custom-webpack": "^12.1.0", diff --git a/examples/angular-app/src/app/home/home.component.ts b/examples/angular-app/src/app/home/home.component.ts index 7f36c3dc..916d9b1e 100644 --- a/examples/angular-app/src/app/home/home.component.ts +++ b/examples/angular-app/src/app/home/home.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import TorusSdk from "@toruslabs/torus-direct-web-sdk"; +import TorusSdk from "@toruslabs/customauth"; import { verifierMap, diff --git a/examples/angular-app/src/app/popup-mode-login/popup-mode-login.component.ts b/examples/angular-app/src/app/popup-mode-login/popup-mode-login.component.ts index 48e067d6..f77f6767 100644 --- a/examples/angular-app/src/app/popup-mode-login/popup-mode-login.component.ts +++ b/examples/angular-app/src/app/popup-mode-login/popup-mode-login.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import TorusSdk from "@toruslabs/torus-direct-web-sdk"; +import TorusSdk from "@toruslabs/customauth"; import { verifierMap, diff --git a/examples/angular-app/src/app/redirect-mode-auth/redirect-mode-auth.component.ts b/examples/angular-app/src/app/redirect-mode-auth/redirect-mode-auth.component.ts index e7ec54b8..1e040a7d 100644 --- a/examples/angular-app/src/app/redirect-mode-auth/redirect-mode-auth.component.ts +++ b/examples/angular-app/src/app/redirect-mode-auth/redirect-mode-auth.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import TorusSdk from "@toruslabs/torus-direct-web-sdk"; +import TorusSdk from "@toruslabs/customauth"; @Component({ selector: "app-redirect-mode-auth", diff --git a/examples/angular-app/src/app/redirect-mode-login/redirect-mode-login.component.ts b/examples/angular-app/src/app/redirect-mode-login/redirect-mode-login.component.ts index e411a85b..9a94ed03 100644 --- a/examples/angular-app/src/app/redirect-mode-login/redirect-mode-login.component.ts +++ b/examples/angular-app/src/app/redirect-mode-login/redirect-mode-login.component.ts @@ -1,5 +1,5 @@ import { Component, OnInit } from "@angular/core"; -import TorusSdk, { Auth0ClientOptions } from "@toruslabs/torus-direct-web-sdk"; +import TorusSdk, { Auth0ClientOptions } from "@toruslabs/customauth"; import { verifierMap, diff --git a/examples/firebase-example/README.md b/examples/firebase-example/README.md index 9cf4ff72..bf7d9779 100644 --- a/examples/firebase-example/README.md +++ b/examples/firebase-example/README.md @@ -1,12 +1,12 @@ -# Firebase X Torus-direct-web-sdk Demo +# Firebase X customauth Demo ## Firebase Prerequisite - You need to have created a Firebase Project in the -[Firebase Console](https://firebase.google.com/console/) as well as configured a web app. + [Firebase Console](https://firebase.google.com/console/) as well as configured a web app. - Enable the Auth providers you would like to offer your users in the firebase console, under -Auth > Sign-in methods. + Auth > Sign-in methods. - Copy `public/sample-config.js` to `public/config.js`: @@ -18,11 +18,12 @@ Then copy and paste the Web snippet code found in the console (either by clickin your web app" button in your Project overview, or clicking the "Web setup" button in the Auth page) in the `config.js` file. -## Torus-direct-web-sdk Prerequisite +## customauth Prerequisite - Create a custom verifier from [torus developer dashboard](https://developer.tor.us) with following configuration: - Make sure to add a following JWT validation fields in custom verifier window:- + - `aud`: firebase project id. - `iss`: 'https://securetoken.google.com/ @@ -34,13 +35,13 @@ in the `config.js` file. ## How it works -- In app.js file, when user is succesfully logged in, it fetches user's `idToken` and `uid` inside firebase sdk's `onAuthStateChanged` callback and passes it to `getTorusKey` function of torus-direct-web-sdk for constructing user's private key. +- In app.js file, when user is succesfully logged in, it fetches user's `idToken` and `uid` inside firebase sdk's `onAuthStateChanged` callback and passes it to `getTorusKey` function of customauth for constructing user's private key. ``` firebase.auth().onAuthStateChanged(async function(user) { ... ... - + if (user) { // fetch the id token of loggedIn user const idToken = await firebase.auth().currentUser.getIdToken(/* forceRefresh */ true); @@ -51,7 +52,7 @@ in the `config.js` file. firebase.auth().currentUser.uid, { verifier_id: firebase.auth().currentUser.uid }, idToken, - ); + ); handleSignedInUser(user, privateKey, publicAddress) } else { handleSignedOutUser(); @@ -68,8 +69,9 @@ npm install ``` ## Start + Run: ```bash npm run install -``` \ No newline at end of file +``` diff --git a/examples/firebase-example/public/app.js b/examples/firebase-example/public/app.js index c926830f..49c3e053 100644 --- a/examples/firebase-example/public/app.js +++ b/examples/firebase-example/public/app.js @@ -215,7 +215,7 @@ var initApp = async function () { // document.getElementById("email-signInMethod-emailLink").addEventListener("change", handleConfigChange); // // Check the selected email signInMethod mode. // document.querySelector('input[name="emailSignInMethod"][value="' + getEmailSignInMethod() + '"]').checked = true; - torusdirectsdk = new window.DirectWebSdk.default({ + torusdirectsdk = new window.CustomAuth.default({ baseUrl: `${window.location.origin}`, redirectPathName: "/", enableLogging: true, diff --git a/examples/firebase-example/public/index.html b/examples/firebase-example/public/index.html index 4a175c0b..7cac1431 100644 --- a/examples/firebase-example/public/index.html +++ b/examples/firebase-example/public/index.html @@ -2,20 +2,20 @@ - Torus Direct Web Sdk X FirebaseUI Demo + Torus CustomAuth Sdk X FirebaseUI Demo - +
-

Torus Direct Web Sdk X FirebaseUI Demo

+

Torus CustomAuth Sdk X FirebaseUI Demo

Loading...