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.
Join the DZone community and get the full member experience.Join For Free
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.
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.
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.
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.