Heroku Node Express Stormpath 'API key ID and secret is required'

863 Views Asked by At

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?

2

There are 2 best solutions below

1
On

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.

0
On

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