gpt4 book ai didi

node.js - Kerberos 库未安装

转载 作者:太空宇宙 更新时间:2023-11-04 01:47:43 27 4
gpt4 key购买 nike

我有一个简单的项目来测试 Kerberos 身份验证。这是一台 Windows 机器。在我的 package.json 中:

"dependencies": {
"kerberos": "^0.0.24",
"mongodb": "^3.0.10"
}

连接网址:

const url = 'mongodb://userxxx%40XXXXX.XXXXX.COM:Password01@servername:27017/?authMechanism=GSSAPI&authSource=%24external&ssl=true';

但是当我尝试在代码中连接时:

MongoClient.connect(url, (err, client) => { 
if (err) {
console.error(err);

我收到错误消息错误:未安装 Kerberos 库

我尝试破坏node_modules并重新安装所有内容。我尝试在全局和本地安装 kerberos 模块。每次都有相同的一致结果。寻找见解。谢谢。

编辑:安装/编译期间没有错误:

$ yarn add mongodb kerberos
yarn add v1.5.1
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 8 new dependencies.
info Direct dependencies
├─ kerberos@0.0.24
└─ mongodb@3.0.10
info All dependencies
├─ bson@1.0.9
├─ kerberos@0.0.24
├─ mongodb-core@3.0.9
├─ mongodb@3.0.10
├─ nan@2.10.0
├─ require_optional@1.0.1
├─ resolve-from@2.0.0
└─ semver@5.5.0
Done in 23.56s.

编辑2:

C:\Users\username\Projects\node.js\kerberos-test>npm init -y
Wrote to C:\Users\username\Projects\node.js\kerberos-test\package.json:

{
"name": "kerberos-test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}



C:\Users\username\Projects\node.js\kerberos-test>npm install kerberos mongodb
--save

> kerberos@0.0.24 install C:\Users\username\Projects\node.js\kerberos-test\nod
e_modules\kerberos
> (node-gyp rebuild) || (exit 0)


C:\Users\username\Projects\node.js\kerberos-test\node_modules\kerberos>if not
defined npm_config_node_gyp (node "C:\Users\username\AppData\Roaming\npm\node_
modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp
\bin\node-gyp.js" rebuild ) else (node "C:\Users\username\AppData\Roaming\npm
\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
kerberos.cc
worker.cc
security_buffer.cc
security_buffer_descriptor.cc
security_context.cc
security_credentials.cc
win_delay_load_hook.cc
..\lib\win32\wrappers\security_credentials.cc(314): warning C4996: 'Nan::Callba
ck::Call': was declared deprecated [C:\Users\username\Projects\node.js\kerber
os-test\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_credentials.cc(341): warning C4996: 'Nan::Callba
ck::Call': was declared deprecated [C:\Users\username\Projects\node.js\kerber
os-test\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(49): warning C4996: 'Nan::Callback::C
all': was declared deprecated [C:\Users\username\Projects\node.js\kerberos-te
st\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(67): warning C4996: 'Nan::Callback::C
all': was declared deprecated [C:\Users\username\Projects\node.js\kerberos-te
st\node_modules\kerberos\build\kerberos.vcxproj]
C:\Users\username\Projects\node.js\kerberos-test\node_modules\nan\nan.h(161
8): note: see declaration of 'Nan::Callback::Call'
..\lib\win32\wrappers\security_context.cc(612): warning C4311: 'type cast': poi
nter truncation from 'unsigned long *' to 'unsigned long' [C:\Users\username\
Projects\node.js\kerberos-test\node_modules\kerberos\build\kerberos.vcxproj]
..\lib\win32\wrappers\security_context.cc(612): warning C4302: 'type cast': tru
ncation from 'unsigned long *' to 'unsigned long' [C:\Users\username\Projects
\node.js\kerberos-test\node_modules\kerberos\build\kerberos.vcxproj]
base64.c
kerberos_sspi.c
Creating library C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\kerberos\build\Release\kerberos.lib and object C:\Users\username\Pro
jects\node.js\kerberos-test\node_modules\kerberos\build\Release\kerberos.exp
Generating code
Finished generating code
kerberos.vcxproj -> C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\kerberos\build\Release\\kerberos.node
kerberos.vcxproj -> C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\kerberos\build\Release\kerberos.pdb (Full PDB)
npm notice created a lockfile as package-lock.json. You should commit this file.

npm WARN kerberos-test@1.0.0 No description
npm WARN kerberos-test@1.0.0 No repository field.

+ kerberos@0.0.24
+ mongodb@3.0.10
added 8 packages from 13 contributors and audited 8 packages in 22.648s
found 0 vulnerabilities


C:\Users\username\Projects\node.js\kerberos-test>

从其他测试项目复制index.js 文件后:

C:\Users\username\Projects\node.js\kerberos-test>node index.js
Error: Kerberos library is not installed
at SSPI.auth (C:\Users\username\Projects\node.js\kerberos-test\node_module
s\mongodb-core\lib\auth\sspi.js:58:41)
at authenticate (C:\Users\username\Projects\node.js\kerberos-test\node_mod
ules\mongodb-core\lib\connection\pool.js:244:17)
at authenticateLiveConnections (C:\Users\username\Projects\node.js\kerbero
s-test\node_modules\mongodb-core\lib\connection\pool.js:831:7)
at C:\Users\username\Projects\node.js\kerberos-test\node_modules\mongodb-c
ore\lib\connection\pool.js:876:5
at waitForLogout (C:\Users\username\Projects\node.js\kerberos-test\node_mo
dules\mongodb-core\lib\connection\pool.js:867:34)
at Pool.auth (C:\Users\username\Projects\node.js\kerberos-test\node_module
s\mongodb-core\lib\connection\pool.js:874:3)
at Server.auth (C:\Users\username\Projects\node.js\kerberos-test\node_modu
les\mongodb-core\lib\topologies\server.js:922:20)
at Server.auth (C:\Users\username\Projects\node.js\kerberos-test\node_modu
les\mongodb\lib\topologies\topology_base.js:379:30)
at authenticate (C:\Users\username\Projects\node.js\kerberos-test\node_mod
ules\mongodb\lib\authenticate.js:56:23)
at module.exports (C:\Users\username\Projects\node.js\kerberos-test\node_m
odules\mongodb\lib\authenticate.js:112:12)

C:\Users\username\Projects\node.js\kerberos-test>

最佳答案

经过一番挖掘后,我在 mongodb-core/lib/auth/sspi.js 中发现了这个:

try {
Kerberos = require_optional('kerberos').Kerberos;
// Authentication process for Mongo
MongoAuthProcess = require_optional('kerberos').processes.MongoAuthProcess;
} catch (err) {} // eslint-disable-line

问题是它默默地捕获错误并且不报告任何内容。将 console.log(err) 放入 catch 后,我看到以下错误:

Error: optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]
sspi.js:34
code:"OPTIONAL_MODULE_NOT_FOUND"
message:"optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]"
stack:"Error: optional dependency [kerberos] found but version [0.0.24] did not satisfy constraint [^0.0.23]\n at require_optional (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\require_optional\index.js:109:19)\n at Object.<anonymous> (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\mongodb-core\lib\auth\sspi.js:29:14)\n at Module._compile (module.js:643:30)\n at Object.Module._extensions..js (module.js:654:10)\n at Module.load (module.js:556:32)\n at tryModuleLoad (module.js:499:12)\n at Function.Module._load (module.js:491:3)\n at Module.require (module.js:587:17)\n at require (internal/module.js:11:18)\n at Object.<anonymous> (c:\Users\apolkousky\Projects\node.js\kerberos-test\node_modules\mongodb-core\lib\connection\pool.js:25:10)"
__proto__:Object {constructor: , name: "Error", message: "", …}

将 kerberos 降级到版本 0.0.23 解决了该问题。

关于node.js - Kerberos 库未安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50844414/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com