Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

How to use the access token variable instead of hardcode ti ImportAccountJSON

navneetv
Regular Contributor II
Regular Contributor II

Hi Team,

Please advise or help me on how I can use the access_token variable in HTTP header authorization. It is working with the Hardcode API key but when I changed something in connection JSON and try to use the token variable. It is not working. Nothing data comes. What changes do I need to enter so that the API key can be stored in the access token's variable and it can be used in import JSON?

We can't use the hardcoded token value in Import JSON. it can be a problem during the Audit. Please advise?

Connection JSON

{
"authentications": {
"acctAuth": {
"authType": "Basic",
"httpParams": {},
"httpHeaders": {
"x-api-key": "API_key",
"contentType": "application/json"
},
"authError": [
"InvalidAuthenticationToken",
"Couldn’ t aunthenticate you",
"AuthenticationFailed"
],
"errorPath": "error",
"retryFailureStatusCode": [
401,
403
],
"maxRefreshTryCount": 5,
"tokenType": "Basic",
"accessToken": "Basic abcd"
}
}
}
 
4 REPLIES 4

khalidakhter
Saviynt Employee
Saviynt Employee

Hi,

REST Connector provides the capability to store any info in the connection JSON and can be referred to import and provisioning JSONs. 
Providing an example for the same.

Connection JSON: A custom attribute named x-api-key is defined in the connection JSON with a dummy value.

{
  "authentications": {
    "userAuth": {
      "authType": "oauth2",
      "httpHeaders": {
        "Accept": "application/json"
      },
      "authError": [
        "InvalidAuthenticationToken",
        "ExpiredAuthenticationToken"
      ],
      "url": "https://login.microsoftonline.com/********-4bba-4287-9f10-**********/oauth2/token",
      "httpMethod": "POST",
      "httpContentType": "application/x-www-form-urlencoded",
      "errorPath": "error.code",
      "maxRefreshTryCount": 3,
      "tokenResponsePath": "access_token",
      "tokenType": "Bearer",
      "authHeaderName": "Authorization",
      "accessToken": "Bearer SDFGFDZSDFCVGBN",
      "x-api-key": "SDFGFDZSDFCVGBN",
      "httpParams": {
        "grant_type": "client_credentials",
        "resource": "https://graph.microsoft.com/",
        "client_secret": "KECNiP**********************************",
        "client_id": "**********-4270-42df-aacf-**********"
      },
      "retryFailureStatusCode": [
        401
      ]
    }
  }
}

Now, you can now refer its value using a binding variable named connection in the import JSON. Example: ${connection.x-api-key}

{
  "accountParams": {
    "connection": "userAuth",
    "processingType": "SequentialAndIterative",
    "successResponses": {
      "statusCode": [
        200
      ]
    },
    "call": {
      "call1": {
        "callOrder": 0,
        "stageNumber": 0,
        "http": {
          "url": "https://0123c31e-871d-4615-ba95-8a3247d905c7.mock.pstmn.io/getAccount",
          "httpHeaders": {
            "Authorization": "${connection.x-api-key}"
          },
          "httpContentType": "application/json",
          "successResponses": {
            "statusCode": [
              200,
              201
            ]
          },
          "httpMethod": "GET"
        },
        "listField": "Accounts",
        "keyField": "accountID",
        "colsToPropsMap": {
          "accountID": "Cnum~#~char",
          "name": "Email~#~char",
          "displayname": "Email~#~char"
        }
      }
    }
  },
  "entitlementParams": {},
  "acctEntParams": {}
}

 

navneetv
Regular Contributor II
Regular Contributor II

Hi Khalid,

I tried with the above connection and ImportJSON which you have shared. Users account is not being imported to Saviynt. 

it works when I used hardcode value to imortJSON with the below connection JSON.

connection JSON

{
"authentications": {
"acctAuth": {
"authType": "Basic",
"httpParams": {},
"httpHeaders": {
"x-api-key": "<enter API_KEY>",
"contentType": "application/json"
},
"authError": [
"InvalidAuthenticationToken",
"Couldn’ t aunthenticate you",
"AuthenticationFailed"
],
"errorPath": "error",
"retryFailureStatusCode": [
401,
403
]
}
}
}
 
ImportAccountJSON
{
"accountParams": {
"connection": "acctAuth",
"processingType": "SequentialAndIterative",
"statusAndThresholdConfig": {
"inactivateAccountsNotInFile": false,
"accountThresholdValue": 20
},
"call": {
"call1": {
"callOrder": 0,
"stageNumber": 0,
"http": {
"httpHeaders": {
"x-api-key": "<enter API_KEY>",
"Accept": "application/json"
},
"httpContentType": "application/json",
"httpParams": {},
"httpMethod": "GET"
},
"listField": "",
"keyField": "accountID",
"colsToPropsMap": {
"accountID": "name~#~char",
"name": "name~#~char",
"status": "status~#~char",
"customproperty1": "name~#~char",
"customproperty2": "status~#~char",
"customproperty3": "lastUpdated~#~char",
"customproperty4": "created~#~char",
"customproperty5": "memberOf~#~char",
"customproperty31": "STORE#ACC#ENT#MAPPINGINFO~#~char"
}
}
},
"acctEntMappings": {
"role": {
"listPath": "memberOf",
"idPath": "",
"keyField": "entitlementID"
}
}
},
"entitlementParams": {
"connection": "acctAuth",
"processingType": "SequentialAndIterative",
"entTypes": {
"role": {
"entTypeOrder": 0,
"call": {
"call1": {
"callOrder": 0,
"stageNumber": 0,
"http": {
"httpHeaders": {
"x-api-key": "<enter API_KEY>",
"Accept": "application/json"
},
"httpContentType": "application/json",
"httpParams": {},
"httpMethod": "GET"
},
"listField": "",
"keyField": "entitlementID",
"colsToPropsMap": {
"entitlementID": "name~#~char",
"entitlement_value": "name~#~char",
"customproperty1": "name~#~char",
"customproperty2": "description~#~char"
},
"makeProcessingStatus": false,
"disableDeletedEntitlements": "true"
}
}
}
}
},
"acctEntParams": {
"processingType": "acctToEntMapping"
}
}

could you please suggest how I can add an access token to the connection that can be used in HTTP header's authentication in ImportJSON?

Like 

"x-api-key": "${access_token}",

 

khalidakhter
Saviynt Employee
Saviynt Employee

Hi,

I have provided a sample to understand the configuration for referring any value from connection JSON to any other JSON in REST Connector.

However in your case, you need to update a few things in the connection JSON.

1. You need to use Oauth2 type connection JSON
2. Populate the authHeaderName attribute as x-api-key
3. Set the attribute named tokenType as empty

you can use the JSON provided below by updating the actual x-api-key value.

{
  "authentications": {
    "acctAuth": {
      "authType": "oauth2",
      "httpHeaders": {
        "Accept": "application/json"
      },
      "authError": [
        "InvalidAuthenticationToken",
        "ExpiredAuthenticationToken"
      ],
      "url": "https://login.microsoftonline.com/********-4bba-4287-9f10-**********/oauth2/token",
      "httpMethod": "POST",
      "httpContentType": "application/x-www-form-urlencoded",
      "errorPath": "error.code",
      "maxRefreshTryCount": 3,
      "tokenResponsePath": "access_token",
      "tokenType": "",
      "authHeaderName": "x-api-key",
      "accessToken": "SDFGFDZSDFCVGBN",
      "xapikey": "SDFGFDZSDFCVGBNTesting",
      "httpParams": {
        "grant_type": "client_credentials",
        "resource": "https://graph.microsoft.com/",
        "client_secret": "KECNiP**********************************",
        "client_id": "**********-4270-42df-aacf-**********"
      },
      "retryFailureStatusCode": [
        401
      ]
    }
  }
}

Now, use the below format of header in the httpHeaders section of your import JSON.
"x-api-key": "${connection.xapikey}"

 

navneetv
Regular Contributor II
Regular Contributor II

Hi @khalidakhter thankyou for working on it it is working now.