Bluemix SSO Node.JS:社交媒体认证

时间:2016-09-17 23:21:32

标签: node.js single-sign-on ibm-cloud

Bluemix; Node.js的; SSO; CWOAU0062E

我一直专注于SSO的男性样本应用程序,但个人无法让它工作。

收到错误消息: CWOAU0062E:OAuth服务提供商无法重定向请求,因为重定向URI无效。请与系统管理员联系以解决问题。

此时的网址为:https://mzsso-yyyyyyyyyyyy.iam.ibmcloud.com/idaas/oidc/endpoint/default/authorize?response_type=code&client_id=cWs2hkNjHz&redirect_uri=https%3A%2F%2Fmzibmsso.mybluemix.net%2Fauth%2Fsso%2Fcallback&scope=openid%20openid

(请注意,xxxxx,yyyyy,zzzzz等是我的蒙面私人标识符......

1)错误消息:CWOAU0062E:OAuth服务提供商无法重定向请求,因为重定向URI无效。请与系统管理员联系以解决问题。 点击我的/登录网址后发生这种情况......

2)我的bluemix门户网站没有“集成”,但是我正在使用“新的bluemix门户网站”

3)谷歌测试,并使用Bluemix中的验证按钮验证确定

)4)使用Bluemix中的验证按钮测试并验证了ok

5)我在线探索的所有样本和支持似乎都是+ 1岁,我所有的代码组合/变体都会产生同样的错误信息。

)它是否适用于本地测试(请注意本地开发人员缺少https)(我需要在google中的重定向问题中添加“localhost:3000”吗?

6a)本地运行不支持https,这是否会影响任何为了开发目的而在本地运行的能力?

6b)目前我需要经常 cf推送我的应用程序,因为我的不确定性和SSO的一般问题。我已经失去了尝试在本地测试它的信心,因为它在服务器上出现了一个带有准系统项目的失败。

)7“回调网址”和“重定向网址”之间是否存在差异(来自google,bluemix和callback_url的上下文)

8)我的代码没有直接引用“google”或“facebook”。我是否忘记了一些显而易见的事情,或者Bluemix SSO背后的想法是否使我的应用提供商无关?

var express = require('express');

var app = express();
var mzSession = require('express-session');

var passport = require('passport');
var cookieParser = require('cookie-parser');
var OpenIDConnectStrategy = require('passport-idaas-openidconnect').IDaaSOIDCStrategy;

app.use(mzSession({
    secret : 'mzSSOSource',
    resave : false,
    saveUninitialized : true
}));

app.use(cookieParser());

app.use(passport.initialize());
app.use(passport.session());

passport.serializeUser(function(user, done) {
    done(null, user);
});

passport.deserializeUser(function(obj, done) {
    done(null, obj);
});

var cfenv = require("cfenv");
var appEnv = cfenv.getAppEnv();
var appServices = appEnv.getServices();

var SSOList = appServices;

if (SSOList.SingleSignOn === undefined) {
    SSOList = {
        "SingleSignOn" : [ {
            "credentials" : {
                "secret" : "xxxxxxxxxx",
                "tokenEndpointUrl" : "https://mzsso-yyyyyyyyyyyy.iam.ibmcloud.com/idaas/oidc/endpoint/default/token",
                "authorizationEndpointUrl" : "https://mzsso-yyyyyyyyyy.iam.ibmcloud.com/idaas/oidc/endpoint/default/authorize",
                "issuerIdentifier" : "yyyyyyyyyy.iam.ibmcloud.com",
                "clientId" : "zzzzzzzzzz",
                "serverSupportedScope" : [ "openid" ]
            },
            "syslog_drain_url" : null,
            "label" : "SingleSignOn",
            "provider" : null,
            "plan" : "professional",
            "name" : "mzSSO",
            "tags" : [ "security", "ibm_created", "ibm_dedicated_public" ]
        } ]
    };
}

var SSOEntryCreds = SSOList.SingleSignOn[0].credentials;

var OpenIDConnectStrategy = require('passport-idaas-openidconnect').IDaaSOIDCStrategy;
var Strategy = new OpenIDConnectStrategy({
    authorizationURL : SSOEntryCreds.authorizationEndpointUrl,
    tokenURL : SSOEntryCreds.tokenEndpointUrl,
    clientID : SSOEntryCreds.clientId,
    scope : 'openid',
    response_type : 'code',
    clientSecret : SSOEntryCreds.secret,
    callbackURL : 'https://mzibmsso.mybluemix.net/auth/sso/callback',
    skipUserProfile : true,
    issuer : SSOEntryCreds.issuerIdentifier
}, function(accessToken, refreshToken, profile, done) {
    process.nextTick(function() {
        profile.accessToken = accessToken;
        profile.refreshToken = refreshToken;
        done(null, profile);
    });
});
passport.use(Strategy);

app.get('/login', passport.authenticate('openidconnect', {}));

function ensureAuthenticated(req, res, next) {
    if (!req.isAuthenticated()) {
        req.session.originalUrl = req.originalUrl;
        res.redirect('/login');
    }
    else {
        return next();
    }
}

app.get('/auth/sso/callback', function(req, res, next) {
    var redirect_url = req.session.originalUrl;
    console.log(redirect_url);
    passport.authenticate('openidconnect', {
        successRedirect : redirect_url,
        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>');
});

app.get('/logout', function(req, res) {
    req.logout();
    res.redirect('/');
});

app.get('/failure', function(req, res) {
    res.send('Login failed');
});

app.get('/', function(req, res) {
    res.send('<a href="/auth/sso/callback">Sign In with a SIS</a>');
});

app.listen(appEnv.port, appEnv.bind, function() {
    console.log('Server listening: ' + JSON.stringify({
        'url' : appEnv.url,
        'bind' : appEnv.bind,
        'port' : appEnv.port
    }));
});
console.log('Server Script Completed');

1 个答案:

答案 0 :(得分:0)

回调网址很可能与应用程序配置的返回URL中设置的不匹配。 请参阅此答案以供参考: https://developer.ibm.com/answers/questions/175319/why-sso-can-not-work.html

对于您的问题#1 - “集成”面板仅在应用程序仪表板的上下文中可用。登录bluemix后,您需要单击应用程序的SSO服务图标,而不是SSO服务本身。

对于#7 callback_url的值和返回URL(来自应用程序仪表板)应该是相同的。返回URL将成为发布此链接的redirect_uri https://mzsso-yyyyyyyyyyyy.iam.ibmcloud.com/idaas/oidc/endpoint/default/authorize?response_type=code&client_id=cWs2hkNjHz& REDIRECT_URI = HTTPS%3A%2F%2Fmzibmsso.mybluemix.net%2Fauth%2Fsso%2Fcallback &安培;范围=的OpenID%20openid