mpjjonker
mpjjonker

Reputation: 947

ibmcloud-appid: nodejs how to do local development vs running in the IBM Cloud?

I am working with appid-serversdk-nodejs and I have the code working and everything works fine, both locally and in the IBM cloud.

But I have to manually switch the APP-URL (localhost:3000 vs .eu-gb.mybluemix.net) I understand that I can do it without providing the passport settings, but how can I have one code base that works for:

I am talking about this piece of code:

// The redirectUri value can be supplied in three ways:
// 1. Manually in new WebAppStrategy({redirectUri: "...."})
// 2. As environment variable named redirectUri
// 3. If none of the above was supplied the App ID SDK will try to retrieve
// application_uri of the application running on IBM Cloud and append a
// default suffix "/ibm/bluemix/appid/callback"
passport.use(new WebAppStrategy({
tenantId: "removed",
clientId: "removed",
secret: "removed",
oauthServerUrl: "https://eu-gb.appid.cloud.ibm.com/oauth/v4/REMOVED"
redirectUri: "https://REMOVED.eu-gb.mybluemix.net" + CALLBACK_URL
//redirectUri: "http://localhost:3000" + CALLBACK_URL
}));

Update: I have moved the data to the .env file, but this doesn't solve my question.

tenantId: process.env.APPID_tenantId,
clientId: process.env.APPID_clientId,
secret: process.env.APPID_secret,
oauthServerUrl: process.env.APPID_oauthServerUrl,
redirectUri: process.env.APPID_redirectUri + CALLBACK_URL

Now I have to change the .env file, which leads to a new commit and build. I want to leverage the connection between APP-ID and our Node server in the IBM cloud.

I am getting errors if I don't supply the redirectUri or the entire WebAppStrategy

Upvotes: 0

Views: 378

Answers (1)

jarkko
jarkko

Reputation: 76

You are doing the right thing (technically) with process.env.*, there are of course multiple other ways of doing it, but that's another subject (personally I utilize CUPS a lot in these situations, .env leads easily to a situations where you commit the secrets to version control)

I'm sure you have given all the url:s as redirect uri:s at the App ID instance ( which would anyway give quite distinctive error if that was the problem ).

You're not sharing what errors are those, that you are getting, but there are a few things you can check.

a) The olders trick in the book - make some debug outputs on your logic to verify that the values you set as environment variables, are actually present at runtime.

b) As you usually do https in cloud but http locally, you might need to set conditionally cookie: { secure: true } only for the cloud deployment, not locally.

Upvotes: 1

Related Questions