Table of contents:
- 1. Omnia Radix Auth Example (OIDC)
To run this sample you will need the following::
- A O365 account
- Access to Azure tenant to register application
Create an application in your Azure tenant using App registrations. Give the application a cool name, select account type (I selected "account in this organization directory only"). You can leave the "redirect URI" open. A few settings that you will have to define:
Authentication:Redirect URI
-> The url where authentication requests are returned. We usehttp://localhost:3000/auth/openid/return
in the example when running the code on localhost. If the app is deployed else where, this should be updated in both Azure and in the app config.Advanced setting:Implicit grant
-> SelectID Tokens
Certificates:Client secrets
> Create a secret for your application. Keep it out of source code!- Make a note of Application Id assigned to your app, you'll need it soon.
- Make a note of the Tenant id as well. That will also become handy quite soon.
Provide the parameters in exports.creds
in config.js as instructed.
- Update
<tenant_name>
inexports.identityMetadata
with the Azure AD tenant name of the format *.onmicrosoft.com. - Update
exports.clientID
with the Application Id noted from app registration. - Update
exports.clientSecret
with the Application secret noted from app registration. - Update
exports.redirectUrl
with the Redirect URI noted from app registration.
Secrets and private information must be kept outside version control. The application supports reading part of the configuration from environment variables (takes precedence over config.js)
Example localconfig.env
export IDENTITYMETADATA=""
export CLIENTID=""
export REDIRECTURL=""
export CLIENTSECRET=""
export DESTROYSESSIONURL=""
Remember to escape special chars like $ in the environment variables (like secrets) when running locally. Remove the escaping when using in Radix (in the radixconfig.yaml and in secrets in the web console)
Optional configuration for production apps:
- Update
exports.destroySessionUrl
in config.js, if you want to use a differentpost_logout_redirect_uri
.
Remember to install dependencies before you run the application
$ npm install
Source config (dependent on OS)
$ source localconfig.env
Linting the application
$ npm run lint
Testing the application
$ npm test
Running the application
$ npm start
Grunt is of several tasks runners available in the Node eco-system. To use Grunt please install the cli.
npm install -g grunt-cli
Using grunt to watch for changes and then run linting and tests
$ grunt
Examine the Grunfile.js
for other tasks that can be executed using Grunt.
docker build -t <imagename> .
A few considerations
- The application exposes things on port 3000. Use the -p to change if necessary
- The application need the needs a few environment variables to function properly. Check the section on storing secrets outside code.
docker run -p 3000:3000 \
--env IDENTITYMETADATA=<> \
--env CLIENTID=<> \
--env REDIRECTURL=<> \
--env CLIENTSECRET=<> \
--enc DESTROYSESSIONURL=<> \
<imagename>
To deploy the application to Omnia Radix you need access to the DevOps platform. If you can open the Web console you should be ok with this. In the web console you'll find the proper instruction for how to get started with defining the application for Radix deployment.
A few important remarks may be in order:
- The
radixconfig.yaml
is the declarative description of what services you want goin in Radix for your application. Radix willonly
use the radixconfig.yaml from the master branch! - When authenticating with Azure AD, remember to define the proper
redirect url's
both in the components environment variables as well as in the Azure AD App registration. - Radix uses
AD groups
to govern access to developing your application. At the time of writing you'll need the guid for these, not the name.
Logging to an external provider is added as an example. Logz.io has been tested. To enable the logging to Logz.oi please do the following:
- Set the
logzio
key totrue
in the config file config.js - Alternatively you can define the environment variable
LOGZIO
and give it the string value"true"
. - Store the token you have gotten from Logz.io in an environment variable named
LOGZTOKEN
. This has to be reflected in your runtime environment - such as Docker.
An example liveness probe is available on /monitoring/alive
. It will basically return a 200 if the app is ready to do it's work, 500 if not.
Based on the example AppModelv2-WebApp-OpenIDConnect-nodejs