Token Returned in Cookie
  • 15 Nov 2022
  • Dark
    Light
  • PDF

Token Returned in Cookie

  • Dark
    Light
  • PDF

Article summary

Scenario

This system has two-step authentication, but instead of returning the token in the response body, it returns the token in a cookie like it would to a browser. It also expects the token to be in the cookie in subsequent calls. Another change includes the Accept header set to */*, and the responseData is not JSON.

Changes to the IAP Service Instance Configuration for the Adapter

  • The "auth" field has been changed so the token will be put in the Cookie.
  • The "auth_field_format" has been changed so the format of the Cookie is what the system expects - "gmsSessionID={token}"

IAP Service Instance Configuration Example

"authentication": {
  "auth_method": "request_token",
  "username": "username",
  "password": "password",
  "token": "",
  "invalid_token_error": 401,
  "token_timeout": 180000,
  "token_cache": "local",
  "auth_field": "header.headers.Cookie",
  "auth_field_format": "gmsSessionID={token}"
},

Changes to the action.json File:

  • Notice the different datatype on the response. Setting it to "plain" means the adapter library will do nothing to it.
  • Notice the added headers. This header overrides the adapter library setting of "Accept".

action.json Example

{
  "name": "getToken",
  "protocol": "REST",
  "method": "POST",
  "entitypath": "{base_path}/{version}/authentication/login",
  "requestSchema": "tokenReqSchema.json",
  "responseSchema": "tokenRespSchema.json",
  "timeout": 0,
  "sendEmpty": false,
  "requestSchema": "JSON",
  "responseDatatype": "PLAIN",
  "headers": {
    "Accept": "*/*"
  },
  "responseObjects": [
    {
       "type": "default",
       "key": "",
       "mockFile": "mockdatafiles/getToken-default.json"
    }
  ]
}, 

Changes to the Request Schema File:

There are no changes to the request schema to support this as the system expected the credentials in the body of the token request.

Changes to the Response Schema File:

  • This is where you need to tell the adapter library where to look for the token.
  • The new placement field tells the adapter library to find the token in the header.
  • The external name field still tells it where to find the token, but in this instance, it is which header.
  • Example: adapter-silverpeak

Response Schema Example

{
  "$id": "respTokenSchema.json",
  "type": "object", 
  "$schema": "http://json-schema.org/draft-07/schema#",
  "translate": true,
  "properties": {
    "ph_request_type": {
      "type": "string", 
      "description": "type of request(internal to adapter)",
      "default": "getToken",
      "enum": [
        "getToken"
      ],
      "external_name": "ph_request_type"
    },
    "token": {
      "type": "string",
      "description": "the token returned from system",
      "placement”: "header",
      "external_name": "set-cookie.gmsSessionID"
    }
  },
  "definitions": {}
}

Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.