Heroku Node Express Stormpath的API密钥ID和秘密是必需的'

时间:2015-10-14 15:18:31

标签: node.js express heroku stormpath express-stormpath

我一直关注Heroku Stormpath docs来设置简单的Express应用。我的server.js文件中的代码如下所示:

'use strict';

var express = require('express');
var pg = require('pg');
var stormpath = require('express-stormpath');
var app = express();

app.use(express.static('public'));


app.use(stormpath.init(app, {
  apiKeyFile: '/.stormpath/apiKey.properties',
  apiKeyId:     process.env.STORMPATH_API_KEY_ID,
  apiKeySecret: process.env.STORMPATH_API_KEY_SECRET,
  secretKey:    process.env.STORMPATH_SECRET_KEY,
  application:  process.env.STORMPATH_URL,
}));

app.set('port', (process.env.PORT || 5000));

app.listen(app.get('port'), function(){
  console.log('Node app is running on port', app.get('port'));
});

请原谅我是Stormpath的新手。我也查看了Express-Stormpath文档,但在本地运行应用程序时仍然收到以下错误:

Node app is running on port 5000
events.js:141
  throw er; // Unhandled 'error' event
  ^

Error: API key ID and secret is required.

我已经通过Heroku配置了Stormpath插件,并且当在终端中运行heroku config时,我看到传递到stormpath.init的所有变量都可用。有人可以告诉我我做错了什么吗?

2 个答案:

答案 0 :(得分:1)

如果你在本地运行你的服务器应用程序,我猜你没有创建环境变量,所以试试这个:

$ STORMPATH_API_KEY_ID=123 STORMPATH_API_KEY_SECRET=secret STORMPATH_SECRET_KEY=secret STORMPATH_URL=url node app.js

或者您可以根据情况设置风暴值:

app.use(stormpath.init(app, {
  apiKeyFile: '/.stormpath/apiKey.properties',
  apiKeyId:     process.env.STORMPATH_API_KEY_ID || 'key',
  apiKeySecret: process.env.STORMPATH_API_KEY_SECRET || 'secret',
  secretKey:    process.env.STORMPATH_SECRET_KEY || 'key',
  application:  process.env.STORMPATH_URL || 'url'
}));

在任何一种情况下都会在你的插件中提供你真实的stormpath值。

答案 1 :(得分:1)

这适用于要解决此问题的任何人。您应该参考Getting started steps provided by Stormpath

对于express.js,请参阅this

这可能是你错过的......

设置环境变量:UNIX

    export STORMPATH_CLIENT_APIKEY_ID=5EFMBEN6N34AU36ENEEGJ9YLY
    export STORMPATH_CLIENT_APIKEY_SECRET=iII3MZPC2hJC/yuOXMjaa0/0GcgyeApfPVvWyNmMR1c
    export STORMPATH_APPLICATION_HREF=https://api.stormpath.com/v1/applications/7F0kZw0wqcFBNh1dDbWMiU

设置环境变量:WINDOWS

    set STORMPATH_CLIENT_APIKEY_ID=5EFMBEN6N34AU36ENEEGJ9YLY
    set STORMPATH_CLIENT_APIKEY_SECRET=iII3MZPC2hJC/yuOXMjaa0/0GcgyeApfPVvWyNmMR1c
    set STORMPATH_APPLICATION_HREF=https://api.stormpath.com/v1/applications/7F0kZw0wqcFBNh1dDbWMiU