Sie sind auf Seite 1von 5

The dissected Node Js application flow can be followed as below.

The application
can be download at From the master, select

Step 1 – The user tries to access an IDCS protected resource/SAML Integrated

application SP URL

Step 2 – Since IDCS is the IDP, the users are routed to IDCS for authentication. As
the custom login page is setup as the authentication page(http://localhost:3000 for
example), the user is redirected to http://localhost:3000/index.html

Step 3 – The code that traps this request should be able to look for
the loginCtx and Signature in the header and should be able to decrypt it. Once the
body has been decrypted, it needs to be redirected to the page/code that will handle
the authentication request"/", function (req, res, next) {

// take loginCtx from the the POST data and decode it
logger.log("POST received.")

logger.log("POST body:\n" + JSON.stringify(req.body,null,2));

// in 18.3.+ /social/callback sends us back here

// social user is in IDCS and no MFA
if (req.body.authnToken) {
redirectBrowser( req, res, "../../signin.html", {
"IDPAuthnToken": req.body.authnToken

Once the body is decrypted and the control routed to the page signin.html, for the
custom authentication piece to work successfully, the sign in application needs to
know the initial state of IDCS. This initial state is the decrypted body(loginContext)
from the request in above code.

In our case, the initial state would be a successful oauth token generation from the
client id and secret. The application will look for an attribute “requeststate” from the
json object and verify whether the attribute status is “success”

{'[IdcsAuthnSDK] Initializing authentication with
existing initial state from IDCS.');
var initialData = JSON.parse( );'[IdcsAuthnSDK] InitialData:
' +;

if (initialData.status === 'success') {;'[IdcsAuthnSDK] status==success');;;;
if ((initialData.requestState) &&
(initialData.nextOp.indexOf('credSubmit') >= 0) &&
>= 0)) {'[IdcsAuthnSDK] Displaying signin form');"USERNAME_PASSWORD","submitCreds",initial
//inject error coming back from social/callback endpoint if
IDCS is not able to match
//external user to locally deactivated user.... plus other
errors like eg if user cancels
//external idp authentication... etc... this error is relayed
to this page via /v1/error endpoint
//which injects it into sessionStorage...
if (error != null){;

Step 4: If the status is “success” then the next step is to formulate the payload for
the /sso/v1/sdk/authenticate API. This API requires a bearer token obtained from the
steps above, the username and password entered in the login form provided at
signin.html. Once the user enters the username and password, the application
captures the input.

Step 5: As per the regulations used for XMLHttpRequest object, the first step is to
get the options allowed for /sso/v1/sdk/authenticate API. Once it receives the
options, it selects the option with “Username” and “Password” and attaches a bearer
token to the API request"POST", app.baseUri + "/sso/v1/sdk/authenticate");

xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer
" +;

// xhr.setRequestHeader("Cookie","Testing=Testing");
console.log('This is where the authentication request is sent
catch(e) { //this should never happen;;
Payload data looks like below:

LoginApp: [IdcsAuthnSDK] Authenticating with:


Step 6: If the authentication is successful, the API returns the control back to the
application with a 200 OK status and a response header as Authentication Token. At
this point the user is authenticated successfully. Now, the next step is to create an
IDCS session for the user who was able to authenticate successfully using the
Authentication Token received.

xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log("The response received is " + this.responseText); ('Authenticate response:
' +;
const jsonResponse = JSON.parse(this.responseText);

if (jsonResponse.status === 'success') {

if (jsonResponse.authnToken) { // User is successfully
authenticated!'[IdcsAuthnSDK] Credentials successfully
document.cookie = "user_authenticated=true;secure";

this.createSession = function(payload) {

var addParam = function(myform, paramName, paramValue) {

param = document.createElement("input");
param.value = paramValue; = paramName;
console.log(param.value + ' ' +;
};'[IdcsAuthnSDK] Creating session with

authnToken:' + + ' ' + payload);
console.log('Creating Session');

var myform = document.createElement("form");

myform.method = "POST";
myform.action = app.baseUri + "/sso/v1/sdk/session"; = "_top";
addParam(myform, "authnToken", payload.authnToken);
if (payload.trustToken) {'[IdcsAuthnSDK] trustToken added.');
addParam(myform, "trustToken", payload.trustToken);
//adding this to flush session after successful login...

This is done by a dynamic form submission for the API "/sso/v1/sdk/session”. The
response is a 302 redirect to the Redirect URL of the Application after which the user
is presented with the application’s redirect url setup in the configuration.

This ends a successful authentication.

Simple explanation of this flow is attached:

The basic username/password Authentication API log in flow consists of the

following REST calls:
1. Instead of presenting the default sign-in page, Oracle Identity Cloud Service
responds to the authorization code URL request with an HTML code that
contains hidden HTML form with two parameters: signature and loginCtx.
2. The browser receives the HTML code, which contains JavaScript to
automatically submits the form to the sample sign-in application.
3. The sample sign-in application decrypts the loginCtx parameter. This
parameter contains some important attributes:
o requestState: Defines the state of the authentication process. It needs
to be used in future POSTs and GETs to Oracle Identity Cloud
Service's Authentication API endpoints.
o nextOp: Defines the next operation the custom sign-in application
must perform.
o nextAuthFactors: Lists the possible authentication factors the sign-in
page must present.
The values of these attributes decides which authentication factor, identity providers,
and social providers must be presented on the page.
4. The browser displays the sign-in page and presents the authentication
factors. The sign-in page includes JavaScript code that is used to perform
AJAX calls to Oracle Identity Cloud Service.
5. After the user enters the USERNAME and PASSWORD, and clicks SIGN
IN, the browser sends a POST request to
the/sso/v1/sdk/authenticate endpoint with the following payload:
o requestState: The value received in a previous response.
o op: The operation being executed. In this example, credSubmit.
o authFactor: The authentication factor being used. In this
o The user credentials. In this example, as value for
the username and password parameters.
The access token that was retrieved at the application's startup is sent as a Bearer
Authorization header.
Note: Before posting the data to Oracle Identity Cloud Service via AJAX, the browser
sends an OPTIONS request to the/sso/v1/sdk/authenticate endpoint to verify if the
browser is authorized to post data to Oracle Identity Cloud Service.
6. The application receives a status code of 200 and an authnToken from the
previous post.
7. The application then sends a POST request to
the /sso/v1/sdk/session endpoint to create the user session in Oracle
Identity Cloud Service.
8. The application receives a 302 or 303 status code and a Location response
header that contains the callback URL with a valid authorization code.
9. The browser then redirects to the specified location, so that the application
can finish its authentication process with Oracle Identity Cloud Service.
By this time, the OpenID Connect flow is finished, and the application can
exchange the authorization code for an ID token.