从Bluemix中的SSO服务器读取已登录的用户详细信息

从Bluemix中的SSO服务器读取已登录的用户详细信息

本文介绍了从Bluemix中的SSO服务器读取已登录的用户详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Cloudant数据库开发Node.js应用程序.我能够通过SSO服务在Blue mix上使用SSO服务器进行IBM IDP身份验证.

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.

我的问题在成功通过身份验证之后发生,我无法获取可以为我提供所需的所有用户属性的JSON对象,例如,登录用户是否是经理?如果是,那么他的序列号,姓名等

My issue occurs after successful authentication, I am unable to get JSON object that can give me all the user attributes that I need, for example, is the logged in person a manager? if yes then his serial number, name etc

有人知道如何从IBM SSO服务检索信息吗?请尽快通知我.

Does anyone know how to retrieve the information from IBM SSO service?Kindly let me know as soon as possible.

推荐答案

您可以检查成功认证后返回的request.user对象.它返回有关已登录用户的一些信息,但是每个提供程序都返回不同的数据.

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.

例如,对于已登录LinkedIn的用户,它返回displayName,firstName,lastName和emailAddress.

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

下面的代码段在应用程序日志中打印request.user JSON对象,因此您可以查看可用的对象并根据需要进行检索.

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

查看console.log代码的结果.

这篇关于从Bluemix中的SSO服务器读取已登录的用户详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 20:35