我是 Node js 的新手,我想使用 Azure Active Directory 进行身份验证。我按照提到的方式下载了 Node 并安装了 NPM Here
npm install express
npm install ejs
npm install ejs-locals
npm install restify
npm install mongoose
npm install bunyan
npm install assert-plus
npm install passport
npm install passport-azure-ad
之后,根据文档,我遵循了第 3 步:设置您的应用以使用 passport-node-js 策略
这是config.js
exports.creds = {
returnURL: 'https://hpe.onmicrosoft.com/8d332647-xxxx-4xxc-8xx-11776XXXXX',
identityMetadata: 'https://login.microsoftonline.com', // For using Microsoft you should never need to change this.
clientID: '22XXXX9-b5fa-XXXXb-bc7a-XXXXXXXa92a',
clientSecret: 'Srekv8dM1NqP4Sqnxxxxxxxxxxxx', // if you are doing code or id_token code
skipUserProfile: true, // for AzureAD should be set to true.
responseType: 'id_token code', // for login only flows use id_token. For accessing resources use `id_token code`
responseMode: 'query', // For login only flows we should have token passed back to us in a POST
//scope: ['email', 'profile'] // additional scopes you may wish to pass
};
以及文档中提到的我编写的其余代码。
但是当我运行 app.js 时出现问题。
C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-skeleton\node_modules\passport-azure-ad\lib\validator.js:51
throw new TypeError(`Invalid value for ${item}.${checker.error}`);
^
TypeError: Invalid value for redirectUrl.The URL must be valid and be https://
at Object.keys.forEach (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-skeleton\node_modules\passport-azure-ad\lib\validator.js:51:13)
at Array.forEach (native)
at Validator.validate (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-skeleton\node_modules\passport-azure-ad\lib\validator.js:37:28)
at new Strategy (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-skeleton\node_modules\passport-azure-ad\lib\oidcstrategy.js:495:13)
at Object.<anonymous> (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-skeleton\app.js:42:14)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
请帮帮我..
问候 尼昆杰
尝试 1: 我尝试了 Nan yu 建议的代码,但出现错误:
(node:2628) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.html#use-mongo-client
events.js:182
throw er; // Unhandled 'error' event
^
MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-master\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:329:35)
at emitOne (events.js:115:13)
at Pool.emit (events.js:210:7)
at Connection.<anonymous> (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-master\node_modules\mongodb\node_modules\mongodb-core\lib\connection\pool.js:280:12)
at Object.onceWrapper (events.js:318:30)
at emitTwo (events.js:125:13)
at Connection.emit (events.js:213:7)
at Socket.<anonymous> (C:\Nikunj Data\Project\Active Directory\WebApp-OpenIDConnect-NodeJS-master\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:187:49)
at Object.onceWrapper (events.js:316:30)
at emitOne (events.js:115:13)
at Socket.emit (events.js:210:7)
at emitErrorNT (internal/streams/destroy.js:62:8)
at _combinedTickCallback (internal/process/next_tick.js:102:11)
at process._tickCallback (internal/process/next_tick.js:161:9)
最佳答案
请引用代码示例:Azure Active Directory OIDC Web Sample
重定向 URL 应与在 AAD 中为您的应用程序注册的回复 URL 相匹配。在该文档中,它是 http://localhost:3000/auth/openid/return
更新
制作代码示例https://github.com/AzureADQuickStarts/WebApp-OpenIDConnect-NodeJS工作,请引用以下步骤:
登录到 Azure 门户。
在顶部栏上,单击您的帐户,然后在“目录”列表下,选择您要在其中注册应用程序的 Active Directory 租户。
单击左侧导航栏中的更多服务,然后选择 Azure Active Directory。
点击 App registrations 并选择 Add。
为应用程序输入一个友好的名称,例如“WebApp-OpenIDConnect-nodejs”,然后选择“Web 应用程序和/或 Web API”作为应用程序类型。对于登录 URL,输入示例的基本 URL,默认情况下为 http://localhost:3000/ .单击“创建”以创建应用程序。
仍然在 Azure 门户中,选择您的应用程序,单击 Settings,然后选择 Reply URLs。添加回复地址:http://localhost:3000/auth/openid/return,点击保存按钮。
找到应用程序 ID 值并将其复制到剪贴板。打开代码示例中的 config.js 文件,将 clientID 替换为应用程序 ID 值。
设置identityMetadata为租户的域名或guid。
在 Azure 门户中,选择您的应用程序,单击 Settings 并选择 Keys。添加应用 key 并复制到 config.js 中的 clientSecret。
如果您想将 mongoDB session 存储用于 session 中间件,请将 useMongoDBSessionStore 设置为 true,将正确的数据库 url 值更新为 exports.databaseUri。 否则设置 useMongoDBSessionStore 为 false 以使用默认 session 存储。
运行应用。在终端中使用以下命令:node app.js .
打开浏览器,输入 http://localhost:3000 并试用您的应用。
关于javascript - Active Directory 集成问题 Nodejs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45477186/
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
尝试通过RVM将RubyGems升级到版本1.8.10并出现此错误:$rvmrubygemslatestRemovingoldRubygemsfiles...Installingrubygems-1.8.10forruby-1.9.2-p180...ERROR:Errorrunning'GEM_PATH="/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/ruby-1.9.2-p180@global:/Users/foo/.rvm/gems/ruby-1.9.2-p180:/Users/foo/.rvm/gems/rub
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我意识到这可能是一个非常基本的问题,但我现在已经花了几天时间回过头来解决这个问题,但出于某种原因,Google就是没有帮助我。(我认为部分问题在于我是一个初学者,我不知道该问什么......)我也看过O'Reilly的RubyCookbook和RailsAPI,但我仍然停留在这个问题上.我找到了一些关于多态关系的信息,但它似乎不是我需要的(尽管如果我错了请告诉我)。我正在尝试调整MichaelHartl'stutorial创建一个包含用户、文章和评论的博客应用程序(不使用脚手架)。我希望评论既属于用户又属于文章。我的主要问题是:我不知道如何将当前文章的ID放入评论Controller。
首先回顾一下拉格朗日定理的内容:函数f(x)是在闭区间[a,b]上连续、开区间(a,b)上可导的函数,那么至少存在一个,使得:通过这个表达式我们可以知道,f(x)是函数的主体,a和b可以看作是主体函数f(x)中所取的两个值。那么可以有, 也就意味着我们可以用来替换 这种替换可以用在求某些多项式差的极限中。方法: 外层函数f(x)是一致的,并且h(x)和g(x)是等价无穷小。此时,利用拉格朗日定理,将原式替换为 ,再进行求解,往往会省去复合函数求极限的很多麻烦。使用要注意:1.要先找到主体函数f(x),即外层函数必须相同。2.f(x)找到后,复合部分是等价无穷小。3.要满足作差的形式。如果是加
SPI接收数据左移一位问题目录SPI接收数据左移一位问题一、问题描述二、问题分析三、探究原理四、经验总结最近在工作在学习调试SPI的过程中遇到一个问题——接收数据整体向左移了一位(1bit)。SPI数据收发是数据交换,因此接收数据时从第二个字节开始才是有效数据,也就是数据整体向右移一个字节(1byte)。请教前辈之后也没有得到解决,通过在网上查阅前人经验终于解决问题,所以写一个避坑经验总结。实际背景:MCU与一款芯片使用spi通信,MCU作为主机,芯片作为从机。这款芯片采用的是它规定的六线SPI,多了两根线:RDY和INT,这样从机就可以主动请求主机给主机发送数据了。一、问题描述根据从机芯片手
文章目录git常用命令(简介,详细参数往下看)Git提交代码步骤gitpullgitstatusgitaddgitcommitgitpushgit代码冲突合并问题方法一:放弃本地代码方法二:合并代码常用命令以及详细参数gitadd将文件添加到仓库:gitdiff比较文件异同gitlog查看历史记录gitreset代码回滚版本库相关操作远程仓库相关操作分支相关操作创建分支查看分支:gitbranch合并分支:gitmerge删除分支:gitbranch-ddev查看分支合并图:gitlog–graph–pretty=oneline–abbrev-commit撤消某次提交git用户名密码相关配置g