2 September 2014

OAuth-erize The Nation! With OpenIG 3.0

OpenIG 3.0 was released a couple of weeks ago, with some significant enhancements.  One of which was the ability to protect applications through the use OAuth2 access tokens, with very little effort.

OAuth2 has been around for a while, and provides a lightweight and developer friendly way to leverage authorization services for web and native applications.  To utilise the features of OAuth2 such as access token validation, refresh token to access token exchange and then scope querying by the client application, generally requires code changes within both the client app and resource servers.  This isn't necessarily a bad thing nor particularly complex, but in some circumstances,  you may not have access to the underlying code, or perhaps the app is hosted by a 3rd party.

OpenIG, as it's a reverse proxy, can easily sit in between the user community and the underlying target application.  With a simple edit of a JSON file, OpenIG can be setup to act as both the resource server and client in an OAuth2 or OpenID Connect environment.

The installation of OpenIG is trivial. A simple Java web application that can be dropped into either a Tomcat or Jetty container.  The app bootstraps from a locally stored configuration folder.  A standard config.json file should be created in the ~/.openig/config/ directory (or equivalent home directory on Windows).  This file contains the entire setup for IG, with things such as handlers, chains and clients, that perform the necessary request checking, stripping or parsing of attributes and replay into the target applications.  Of course, one of the benefits of OpenIG, is that itself, can indeed be protected by an OpenAM policy agent, and utilise any attributes that can be passed downstream to IG.

Following the simple example that comes with the OpenIG documentation, setting up integration a an OIDC relying party is pretty quick.  OpenAM can quickly be configured as the OAuth2 provider, as this functionality is available out of the box and configurable via one of the OpenAM Common Tasks wizard.

The example configuration for setting up IG as an OAuth2 client basically has two main components - an overall handler object (OpenIDConnectChain) that initiates the interaction to the OAuth2 provider and an out going handler, that retrieves the necessary attributes from the OIDC scope, and replays them into the target application as the necessary username and password.  There's also a capture filter for logging.  In production, you perhaps wouldn't necessarily replay the password here, but it would depend on the underlying application.

The OpenIDConnectChain, contains an OAuth2ClientFilter object conveniently called OpenIDConnectClient!  This object, contains the necessary OAuth2 provider details - URL, clientID, requested scopes and so on.  The information retrieved by the request is actually stored in the target attribute - ${exchange.openid}.  This attribute can then be queried by the out going chain, namely the GetCredentials object, which is a Groovy scriptable component.  Being scriptable, means we are pretty free to extend this as we see fit.  In this example, the GetCredentials object, simply pulls out the username and password fields.  Those fields are then passed down to the LoginRequestFilter object, which replays the fields into a form in the protected application.

Mega simple!  The beauty of it, is that underlying application (in this case the Java sample HTTP that comes with the OpenIG document)  requires zero code changes. All of the configuration is abstracted into the OpenIG proxy.

The same process can easily be repeated for other federation protocols such as SAML2.

No comments:

Post a Comment