Quick Start

Integrate DirectAuth in your web application today

To allow your web app to retrieve keys from the Torus Network, we'll be using the direct-web-sdk, the repo itself has examples that you can also refer to:

  1. Install the package npm i @toruslabs/torus-direct-web-sdk

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

  3. Serve service worker 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‚Äč

  4. 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 DirectWebSdk for specific login ( example http://localhost:3000/serviceworker/)

  5. 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

  6. Instantiate the package with your own specific client-id

const torus = new DirectWebSdk({
baseUrl: "http://localhost:3000/serviceworker/",
proxyContractAddress: "0x4023d2a0D330bF11426B12C6144Cfb96B7fa6183", // details for test net
network: "ropsten", // details for test net
});
await torus.init();

7. Trigger the login

const userInfo = await torus.triggerLogin({
typeOfLogin: "google",
verifier: "google",
clientId: "MY CLIENT ID GOOGLE",
});

Reach out to hello@tor.us to get your verifier spun up on the testnet today!

For integration into other mobile, native or other platforms please refer to Integrating DirectAuth.