2

I have been following the Heroku Stormpath docs to setup a simple Express app. The code from my server.js file is shown below:

'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'));
});

Forgive me for being a newbie to Stormpath. I've looked through the Express-Stormpath docs as well, but I continue to receive the following error when running the app locally:

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

Error: API key ID and secret is required.

I have provisioned the Stormpath addon via Heroku, and when running heroku config in the terminal I see that all of the variables passed into stormpath.init are available. Can someone enlighten me as to what I am doing wrong?

jdev03
  • 21
  • 2
  • The error that you have is about running your app locally or in the heroku machine? – Wilson Oct 14 '15 at 15:48
  • @WilsonBalderrama I am running the app locally. I've updated the post to reflect this crucial detail. – jdev03 Oct 14 '15 at 16:09
  • Which version of the express-stormpath library are you using? We made a new release recently which uses new configuration options. You're using the OLD config options. – rdegges Oct 15 '15 at 16:46
  • From [Cody](http://stackoverflow.com/users/3704955/cody): This [github issue](https://github.com/stormpath/stormpath-sdk-node/issues/215) shows they changed the way initiating a client works. There may be a similar issue with the express module. – KyleMit Oct 16 '15 at 14:10
  • @rdegges I am using express-stormpath v2.0.11. Could you please point me to the updated configuration docs? – jdev03 Oct 19 '15 at 15:24

2 Answers2

1

if you are running your server app locally, I can guess that you didn't create the environment variables so try this:

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

or you can set the storm values whenever they are empty as in your case:

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'
}));

in either case provide your real stormpath values from your addon at heroku.

Wilson
  • 9,006
  • 3
  • 42
  • 46
  • I tried this previously, and again after your suggestion. However, I still encounter the exact same error. – jdev03 Oct 14 '15 at 20:04
1

This is for anyone coming for a solution to this problem.. You should refer the Getting started steps provided by Stormpath!

For express.js refer this.

This might be what you were missing..

Set the environment variables: 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

Set the environment variables: 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
Ishan Madhusanka
  • 641
  • 1
  • 11
  • 21