Code Monkey home page Code Monkey logo

user-controlled-access-sample's Introduction

User controlled access

This sample demonstrates a pattern to implement "impersonation" kind of a solution but in a safer and user controlled manner. The sample enables sharing limited access of "my account" to an admin/Helpdesk user to troubleshoot account related issues.

The sample assumes both primary user and the help desk user are assumed to be in the same Auth0 connection.

Run locally

git clone [email protected]:zamd/user-controlled-access-sample.git
cd user-controlled-access-sample
npm i

Auth0 setup

Client setup

  • Create a Regular Web App in Auth0 dashboard

  • Set Allowed Callback Urls. The default setup uses http://localhost:3000/login/callback

  • Create and enable a database connection on this app

  • Create two users in above database connection as:

  • Go to Apis --> Auth0 Management API and authorize Regular Web App client to read:users update:users scopes

  • Copy client_id client_secet to .env file.

  • Sample .env file:

Domain=test-access.auth0.com
ClientID=232323232
ClientSecret=32-4_YTz6Y1uT
CallbackURL=http://loopback.com:3000/login/callback

Rule setup

  • Create user-controlled-access rule with following sample code:
function (user, context, callback) {

var  _  =require('[email protected]');

var  requestedScopes  =  context.request.query  &&  context.request.query.scope.split(' ') || [];

var  targetScope  =  requestedScopes.find(s=>s.indexOf('user_controlled_access')!==-1);

if (targetScope) {

//TODO: validate/verify authorized_access depending on application's domain.

var  onwerId  =  targetScope.split('/')[1];

var  ag  =  user.app_metadata.access_grants.find(ag=>ag.owner_id===onwerId);

context.idToken["http://user.controlled.access/authorized_access"] =  ag;

}

callback(null, user, context);

}

Run

npm start

Sharing

  • Now, logout and login in as [email protected] and you can switch to restricted access view.

Granted_access

user-controlled-access-sample's People

Watchers

James Cloos avatar Zulfiqar Ahmed 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.