Giter Club home page Giter Club logo

multi-tenancy-mfa's Introduction

Multi tenancy with MFA example

This app contains the following tenants with their authentication methods:

  • Public tenant: Email password as first factor with OTP email as second factor
  • Tenant 1: Google workspaces or email password as first factor with TOTP as second factor
  • Tenant 2: Email password, with no second factor
  • Tenant 3: GitHub or OTP email as first factor, with no second factor

Running the example

npm install
npm run start

This will start the React app on http://localhost:3000 and the Node Express server on http://localhost:3001.

Exporting list of users per tenant

There are two ways to see this list:

Multiple frontends with the same backend

This document shows you how you can configure the origin value dynamically on the backend based on the request's host header. This will automatically set the right cookie config so that the session tokens work correctly. One point to note is that if you want to use cookie based sessions and have the frontend be on a different base domain than the backend, then browsers like safari won't allow setting of cookies (since they reject third party cookies). To solve this, you would need to setup a CNAME in your DNS for your backend for each of the frontends such that the backend domain that that frontend queries is in the same base domain (example.com queries api.example.com). Alternatively, you could just use header based sessions.

Security

Login security

Session security:

cURL commands to create and configure tenants

This project relies on certain tenants to be created in the SuperTokens core. Below are the curl commands to create and configure the tenants.

curl --location --request PUT 'https://st-dev-30506dd0-ed09-11ee-ad01-1fdc88939d81.aws.supertokens.io/recipe/multitenancy/tenant' \
--header 'Content-Type: application/json' \
--header 'api-key: etb03yacD9WnwIC22o=MEy4J0V' \
--data-raw '{
    "tenantId": "public",
    "emailPasswordEnabled": true,
    "thirdPartyEnabled": false,
    "passwordlessEnabled": true,
    "firstFactors": ["emailpassword"],
    "requiredSecondaryFactors": ["otp-email"]
}'

curl --location --request PUT 'https://st-dev-30506dd0-ed09-11ee-ad01-1fdc88939d81.aws.supertokens.io/recipe/multitenancy/tenant' \
--header 'Content-Type: application/json' \
--header 'api-key: etb03yacD9WnwIC22o=MEy4J0V' \
--data-raw '{
    "tenantId": "tenant1",
    "emailPasswordEnabled": true,
    "thirdPartyEnabled": true,
    "passwordlessEnabled": false,
    "firstFactors": ["emailpassword", "thirdparty"],
    "requiredSecondaryFactors": ["totp"]
}'

curl --location --request PUT 'https://st-dev-30506dd0-ed09-11ee-ad01-1fdc88939d81.aws.supertokens.io/tenant1/recipe/multitenancy/config/thirdparty' \
--header 'Content-Type: application/json' \
--header 'api-key: etb03yacD9WnwIC22o=MEy4J0V' \
--data-raw '{
  "config": {
    "thirdPartyId": "google-workspaces",
    "name": "Google Workspaces",
    "clients": [
      {
        "clientId": "1060725074195-kmeum4crr01uirfl2op9kd5acmi9jutn.apps.googleusercontent.com",
        "clientSecret": "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",
        "additionalConfig": {
            "hd": "*"
        }
      }
    ]
  }
}'


curl --location --request PUT 'https://st-dev-30506dd0-ed09-11ee-ad01-1fdc88939d81.aws.supertokens.io/recipe/multitenancy/tenant' \
--header 'Content-Type: application/json' \
--header 'api-key: etb03yacD9WnwIC22o=MEy4J0V' \
--data-raw '{
    "tenantId": "tenant2",
    "emailPasswordEnabled": true,
    "thirdPartyEnabled": false,
    "passwordlessEnabled": false,
    "firstFactors": ["emailpassword"]
}'

curl --location --request PUT 'https://st-dev-30506dd0-ed09-11ee-ad01-1fdc88939d81.aws.supertokens.io/recipe/multitenancy/tenant' \
--header 'Content-Type: application/json' \
--header 'api-key: etb03yacD9WnwIC22o=MEy4J0V' \
--data-raw '{
    "tenantId": "tenant3",
    "emailPasswordEnabled": false,
    "thirdPartyEnabled": true,
    "passwordlessEnabled": true,
    "firstFactors": ["thirdparty", "otp-email"]
}'


curl --location --request PUT 'https://st-dev-30506dd0-ed09-11ee-ad01-1fdc88939d81.aws.supertokens.io/tenant3/recipe/multitenancy/config/thirdparty' \
--header 'Content-Type: application/json' \
--header 'api-key: etb03yacD9WnwIC22o=MEy4J0V' \
--data-raw '{
  "config": {
    "thirdPartyId": "github",
    "name": "GitHub",
    "clients": [
      {
        "clientId": "467101b197249757c71f",
        "clientSecret": "e97051221f4b6426e8fe8d51486396703012f5bd"
      }
    ]
  }
}'

multi-tenancy-mfa's People

Contributors

rishabhpoddar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.