Over a million developers have joined DZone.

Authentication in Node.js Applications on Bluemix

There are different ways to do authentication in Node.js applications running on Bluemix—either via Bluemix services, third party offerings, open source libraries, or self-written code. Check out this sample that leverages the Single Sign On service and a Mongo database to store user sessions for cloud-native applications.

· Cloud Zone

Build fast, scale big with MongoDB Atlas, a hosted service for the leading NoSQL database on AWS. Try it now! Brought to you in partnership with MongoDB.

There are different ways to do authentication in Node.js applications running on Bluemix—either via Bluemix services, third party offerings, open source libraries, or self-written code. Below is a sample that leverages the Single Sign On service and a Mongo database to store user sessions for cloud-native applications.

Get the code from GitHub.

The Single Sign On service supports different identity providers. For example enterprise customers typically use SAML. If customers don’t have an SAML identity provider, they can install an Identity Bridge on premises which externalizes the SAML protocol to an LDAP version 3 compliant directory. In the sample below, I use a cloud directory with only one test user, but the application code would be identical when using SAML.

sso-setup-3

In the Node.js application, passport and passport-idaas-openidconnect are used. passport-idaas-openidconnect is a passport authentication strategy for the IBM Bluemix Single Sign On service. Check out authentication.js for details.

The sample code relies on cookies which are sent with the client requests and validated on the server. For cloud-native applications, the validation needs to work when multiple instances of applications are run. My colleague, Tim Robinson, documented in the article Scale single sign-on for your Node.js cloud apps how to do this by leveraging Redis. My sample is very similar but uses Mongo instead of Redis.

Follow the instructions in the README to set up the sample application. Since, as a developer, I prefer to develop locally, I documented how to configure the local development environment. After everything is set up correctly, you’ll be able to log on and access the user information in the server side code.

login-1

Now it's easier than ever to get started with MongoDB, the database that allows startups and enterprises alike to rapidly build planet-scale apps. Introducing MongoDB Atlas, the official hosted service for the database on AWS. Try it now! Brought to you in partnership with MongoDB.

Topics:
bluemix ,cloud ,ibm

Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}