node.js - IdentityServer nodejs token 问题

标签 node.js passport.js openid-connect identityserver3

我正在尝试在身份服务器中授权我的 nodejs 服务器。 我在 nodejs 中使用 passport-openidconnect 库。我的 nodejs 代码:

var express = require('express');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);
var Strategy = require('passport-openidconnect').Strategy;

module.exports.configure = function configure(app, passport) {

    var auth = {
        authorizationURL: 'https://localhost:44333/core/connect/authorize',
        tokenURL: 'https://localhost:44333/core/connect/token',
        userInfoURL: 'https://localhost:44333/core/connect/userinfo',
        clientID: 'NodeJsClient',
        clientSecret: 'fakeSecret',
        callbackURL: '/auth/callback',
        scope: 'openid profile email offline_access',
        responseType: "id_token"
    };

    app.use(session({
            secret: 'someSecret',
            resave: false,
            saveUninitialized: false,
            secure: true,
            store: new RedisStore({
                host: '127.0.0.1',
                port: 6379
            })
        }
    ));

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

    passport.use(new Strategy(auth, function (iss, sub, profile, jwtClaims, accessToken, refreshToken, params, verified) {
        verified(null, Object.assign({}, profile, {token: accessToken}));
    }));

    passport.serializeUser(function (user, done) {
        done(null, {id: user.id, name: user.displayName, token: user.token});
    });

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

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

    app.get('/auth/callback', passport.authenticate('openidconnect', {}),
        function (req, res) {
            if (!req.user) {
                throw new Error('user null');
            }
            res.redirect("/");
        }
    );
};

身份服务器端:

new Client()
                {
                    ClientId = "NodeJsClient",
                    ClientName = "Nodejs Demo Client",
                    AccessTokenType = AccessTokenType.Jwt,

                    ClientSecrets = new List<Secret>()
                    {
                        new Secret("fakeSecret".Sha256())  
                    },

                    Flow = Flows.AuthorizationCode,
                    RedirectUris = new List<string>() { "http://localhost:5200/auth/callback" },
                    AllowedScopes = new List<string>()
                    {
                        Constants.StandardScopes.OpenId,
                        Constants.StandardScopes.Profile,
                        Constants.StandardScopes.Email,
                        Constants.StandardScopes.Roles,
                        Constants.StandardScopes.Address,
                        Constants.StandardScopes.OfflineAccess
                    },

                    AccessTokenLifetime = 3600
                }

当我在允许个人数据权限后尝试授权时出现错误:

InternalOAuthError: failed to obtain access token

我发现在对我的应用程序的重定向请求中没有 token 。问题出在哪儿?你有没有很好的文档化的 nodejs 库来处理

OpenID Connect

最佳答案

我想出了问题在哪里。在 passport-openidconnect 旁边,我发现了更详细的错误:“错误:UNABLE_TO_VERIFY_LEAF_SIGNATURE”。按照 this question 中的描述解决它.此刻的解决方案让我完全满意。

关于node.js - IdentityServer nodejs token 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37543253/

相关文章:

node.js - Express.js 动态路由

Node.js 将十六进制数转换为 byteArray

c# - 使用 Thinktecture IdentityServer3 进行身份验证/授权 native Android 应用程序的正确方法是什么

node.js - DynamoDB 查询 bool 键

sails.js - SailsJS 中不起作用的默认策略

javascript - 如何正确使用 Passport.js?

authentication - oauth2orize 与 API?

oauth - 接受来自多个授权服务器的 token

rest - 发现 OpenID Connect 提供商发行者

javascript - 如何使用 NodeJS 发送带有文件名和文件扩展名的文件流