Read logged in User details from SSO server in Blue mix

后端 未结 1 852
醉话见心
醉话见心 2021-01-28 11:23

I am working on Node.js application with Cloudant database. I was able to do IBM IDP authentication with SSO server on Blue mix via the SSO service.

My issue occurs afte

相关标签:
1条回答
  • 2021-01-28 11:54

    You can check the request.user object returned after successful authentication. It returns some information about the logged in user, but each provider returns different data.

    For example, for LinkedIn logged users it returns displayName, firstName, lastName and emailAddress.

    The snippet code below prints the request.user JSON object in the application log, so you can see what is available and retrieve as needed.

    app.get('/auth/sso/callback', function(req, res, next) { 
    
        var redirect_url = req.session.originalUrl;                
        passport.authenticate('openidconnect', {
            successRedirect: '/hello',                                
            failureRedirect: '/failure',                        
        })(req,res,next);
    });
    
    app.get('/hello', ensureAuthenticated, function(request, response) {
    
        response.send('Hello, '+ request.user['id'] + '!\n' + '<a href="/logout">Log Out</a>');
        console.log(JSON.stringify(request.user));     
    
    });
    

    After user logs in you can run:

    cf logs <app-name> --recent
    

    to see results from console.log code.

    0 讨论(0)
提交回复
热议问题