Coder Social home page Coder Social logo

Comments (4)

derisen avatar derisen commented on June 23, 2024

@jefjos the passport-azure-ad library can log the reasons to console if you set:

loggingNoPII: false 

in config.js.

However there is no feature in the library that would allow you to send these logs to the front-end (there might be other tools for that but I'm not aware of any). What you can do, though, is to set your own validation logic for reasons you care about, and send a response for them with the reason stated. If you actually look at the index.js, there we have:

        if (req.authInfo['scp'].split(" ").indexOf("demo.read") >= 0) {
            // Service relies on the name claim.  
            res.status(200).json({
                'request-for': 'access_token',
                'requested-by': req.authInfo['name'],
                'issued-by': req.authInfo['iss'],
                'issued-for': req.authInfo['aud'],
                'scope': req.authInfo['scp']
            });
        } else {
            console.log("Invalid Scope, 403");
            res.status(403).json({'error': 'insufficient_scope'}); 
        }

You could do something similar for validating the issuer, for example:

if (req.authInfo['iss'] != "https://sts.windows.net/{your-tenant-id}") {
        res.status(403).json({'error': 'invalid issuer'});
}

from active-directory-javascript-nodejs-webapi-v2.

jefjos avatar jefjos commented on June 23, 2024

Thanks @derisen . But if I implement my own logic to do validation, then wouldn't that defeat the purpose of using the library?

from active-directory-javascript-nodejs-webapi-v2.

derisen avatar derisen commented on June 23, 2024

@jefjos sorry I must have misunderstood you. You can pass a "custom callback" function to passport.authenticate(). Take a look at the documentation. The info parameter should tell you the reason for rejection, you can return this then as response.

from active-directory-javascript-nodejs-webapi-v2.

jefjos avatar jefjos commented on June 23, 2024

Thanks @derisen ! This helps me.

from active-directory-javascript-nodejs-webapi-v2.

Related Issues (12)

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.