Skip to content

Commit

Permalink
Rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Nov 10, 2021
1 parent a82d47e commit d29c572
Show file tree
Hide file tree
Showing 49 changed files with 127 additions and 113 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ dist
# TernJS port file
.tern-port

toruslabs-torus-direct-web-sdk-*
toruslabs-customauth-*
bundle.min.js
types2/
.DS_Store
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ typings/


examples/
toruslabs-torus-direct-web-sdk-*
toruslabs-customauth-*
ssl/
src/
scripts/
Expand Down
65 changes: 34 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
Expand All @@ -36,13 +36,13 @@ CDN's serve the non-core-js polyfilled version by default. You can use a differe
jsdeliver

```js
<script src="https://cdn.jsdelivr.net/npm/@toruslabs/torus-direct-web-sdk@4"></script>
<script src="https://cdn.jsdelivr.net/npm/@toruslabs/customauth@5"></script>
```

unpkg

```js
<script src="https://unpkg.com/@toruslabs/torus-direct-web-sdk@4"></script>
<script src="https://unpkg.com/@toruslabs/customauth@4"></script>
```

### Tips for NUXT
Expand All @@ -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
});
Expand All @@ -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)
Expand All @@ -120,32 +120,34 @@ 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
- [angular](examples/angular-app/src/app/app.component.ts) for popup flow
- [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/)

Expand Down Expand Up @@ -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);
Expand All @@ -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)
6 changes: 4 additions & 2 deletions examples/angular-app/README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/angular-app/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions examples/angular-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/angular-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/angular-app/src/app/home/home.component.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
18 changes: 10 additions & 8 deletions examples/firebase-example/README.md
Original file line number Diff line number Diff line change
@@ -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`:

Expand All @@ -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/<firebase-project-id>

Expand All @@ -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);
Expand All @@ -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();
Expand All @@ -68,8 +69,9 @@ npm install
```

## Start

Run:

```bash
npm run install
```
```
2 changes: 1 addition & 1 deletion examples/firebase-example/public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions examples/firebase-example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
<html>
<head>
<meta charset="UTF-8" />
<title>Torus Direct Web Sdk X FirebaseUI Demo</title>
<title>Torus CustomAuth Sdk X FirebaseUI Demo</title>
<link rel="manifest" href="manifest.json" />
<script src="https://www.gstatic.com/firebasejs/7.4.0/firebase.js"></script>
<script src="config.js"></script>
<script src="common.js"></script>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
<script src="https://unpkg.com/@toruslabs/[email protected]/dist/directWebSdk.umd.min.js"></script>
<script src="https://unpkg.com/@toruslabs/[email protected]/dist/customAuth.umd.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/ui/4.8.1/firebase-ui-auth.js"></script>
<link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/4.8.1/firebase-ui-auth.css" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
</head>
<body>
<div id="container">
<h3>Torus Direct Web Sdk X FirebaseUI Demo</h3>
<h3>Torus CustomAuth Sdk X FirebaseUI Demo</h3>
<div id="loading">Loading...</div>
<div id="loaded" class="hidden">
<div id="main">
Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs-app/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Direct Web SDK - NextJS App Notes
# CustomAuth SDK - NextJS App Notes

For installation instructions [click here](https://github.com/torusresearch/torus-direct-web-sdk)
For installation instructions [click here](https://github.com/torusresearch/customauth)

How to run example

Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/nextjs-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"start": "next start"
},
"dependencies": {
"@toruslabs/torus-direct-web-sdk": "file:../../toruslabs-torus-direct-web-sdk-4.14.3.tgz",
"@toruslabs/customauth": "file:../../toruslabs-customauth-4.14.3.tgz",
"error": "10.4.0",
"next": "11.1.1",
"react": "17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-app/pages/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* User will be redirected to this page in redirect uxMode
*/
import React from "react";
import TorusSdk, { RedirectResult } from "@toruslabs/torus-direct-web-sdk";
import TorusSdk, { RedirectResult } from "@toruslabs/customauth";
import dynamic from "next/dynamic";

let ReactJsonView;
Expand Down
Loading

0 comments on commit d29c572

Please sign in to comment.