OpenAM JavaScript Wrapper

OpenAM JavaScript Wrapper

A long time ago I started writing an example of a small web application that was using the OpenAM REST APIs. Once working on this task, I realised it was relatively easy to create wrappers around the ForgeRock APIs in any programming language. I decided to start with a JavaScript wrapper.

I am a bit rusted in this area, and since I was doing it only for fun and on my “idle” time, it took a while.  Anyway, here the openam.js wrapper and the openamUtils.js utility library.

This is a work in progress, and also a JavaScript coding exercise. Initially it is leveraging the Authentication and SSO API’s but with a little help of the community it can be extended to cover the whole set of APIs, inclulding Authorization, OAuth2, OIDC, UMA, STS, etc. It can also be an idea to start similar wrappers for the OpenIDM and OpenDJ REST APIs. It is NOT supported NOR endorsed by ForgeRock. If you feel it is useful, please contribute.

openam.js is a small library/wrapper of some of the REST APIs of OpenAM. The intention is to provide an easy way to integrate the calls in your Client JavaScript code without needing to implement the REST code yourself.

openamUtils.js is another wrapper to render configurable Login Buttons and Login Boxes. It uses openam.js and the css style contained in the github repository, of course you can adjust the css to your needs but it should work nicely out of the box. This wrapper does not need JQuery, but of course you can combine it with any other JS UI framework. In the future I would like to create another library combined with bootstrap.

Several examples are included together with the source code:

Each example is a single web page.

Before trying the library and examples be sure to configure your OpenAM to support CORS (see this blog entry for more info on CORS and OpenAM, hint it involves to modify the web.xml of OpenAM or modify your Web Container -Tomcat for example has CORS support-).

The documentation is available for both libraries here:

Here two videos showing how to use the libraries.

  1. Showing how the libraries work, using the examples included in github:


  2. And here the OpenAM Configuration of the instance used with the examples.



Give the libraries a try and send us your feedback. Again you are more than welcome to contribute.


Comments are closed.

  1. full2 6 years ago

    Some coments:
    I believe there are some little bugs:
    -In logoutWithModernOpenAM
    I believe it must be var logout_url = this.logoutURL(tokenId);
    I believe the tokenId was not being sent/used in the logout.

    Also in that function I believe it must be :
    if ( response ) {
    instead of “this.aMAuthCookie”

  2. Author
    Victor Ake 6 years ago

    Thanks full2. Will check that out, and comeback to you

  3. Author
    Victor Ake 6 years ago

    Indeed, it should be:
    var logout_url = this.logoutURL(tokenId);

    The other part should be OK. Both cookies are deleted:
    if ( response ) {
    deleteCookie(this.sessionCookieName(), this.domainName());
    deleteCookie(this.aMAuthCookie, this.domainName());

    I have patched and committed to github.

    Thanks for the feedback!

©2022 ForgeRock - we provide an identity and access platform to secure every online relationship for the enterprise market, educational sector and even entire countries. Click to view our privacy policy and terms of use.

Log in with your credentials

Forgot your details?