Webservice Refresh Token Issue

:bangbang: Please be sure you’ve read the docs and API specs before asking for help. Also, please be sure you’ve searched the forum for your answer before you create a new topic.

Hi All,
I have configured WSC connector with HTTP operations like test connection, aggregation, entitlement, etc. The token got expired after sometime, how to refresh the token and use it in HTTP operation. The response is in xml format. Tried the below code but it working.

Used custom authentication and created custom auth http operation.

<?xml version='1.0' encoding='UTF-8'?> Before operation rule to retrieve token. <![CDATA[ import java.util.*; import org.w3c.dom.*; import javax.xml.parsers.*; import java.io.StringReader; import org.xml.sax.InputSource; import connector.common.JsonUtil; import sailpoint.connector.webservices.WebServicesClient; import sailpoint.connector.webservices.EndPoint;

try {
String username = (String) application.getAttributeValue(“username”);
String password = (String) application.getAttributeValue(“password”);
WebServicesClient client = new WebServicesClient();
String url = “https://{{lab_server}}:{{port}}/services/auth/login”;
Map args = new HashMap();
args.put(WebServicesClient.ARG_URL, url);
client.configure(args);
// Configure the header
Map header = new HashMap();
header.put(“Content-Type”, “application/xml”);
List allowedStatuses = new ArrayList();
allowedStatuses.add(“2**”);
// Construct the raw XML payload
String payload = “”
+ “” + username + “”
+ “” + password + “”
+ “”;
String response = client.executePost(url, payload, header, allowedStatuses);
// if response contains token it can be updated in the requestEndpoint header or body
// the requestEndpoint will be used for execution of the particular operation configured
log.info("response: " + response);
// Fetch the session token from the response XML
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(response)));
document.getDocumentElement().normalize();
// Assuming the token is in an element named “token”
String apiToken = document.getElementsByTagName(“token”).item(0).getTextContent();
log.info("API token: " + apiToken);
// Add to the requestEndPoint to authenticate to the endpoint
requestEndPoint.addHeader(“Authorization”, apiToken);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
]]>

Any solution would be helpful. Thanks.

Shantha Kumar

Hi @Santhakumar ,

I would like to know if you are performing a bulk access profile addition for the user, to understand why token is expired faster.

Coming to the rule, everything looks ok to me. Have you tried adding a return statement to return updated requestEndPoint object?

I usually add the return statement to have the new values reflected.

Regards,
Uday Kilambi

Hi,

Add the HTTP error codes in the webservices configuration when token needs to be generated again.

image

This will try to generate the token again whenever expired.

-Abhinov

3 Likes

@uday_kilambiCTS I have already try that by adding return requestEndPoint; in the end line of code. But it was throwing error token timed out when i attached this rule to Account aggregation operation.

Whether iam doing it correctly or not i don’t know iam bit confused. If i have gave the token hardcoded in the body of the request payload with rule attached i am not able to do the aggregation. If i remove the rule and try the aggregation with hardcoded token it was successfull.

Also in Account operation Header i have configured Authorization - apiToken and use this variable in the body for token value as $application.apiToken$ is this correct way of doing it?

Hi @Santhakumar ,

Have you tried logging your apiKey that you set in the rule, did you verify if it is returning the right format of apiKey. If you capture the apiKey in the rule, try using it directly on postman or hardcoding it on the header and verify that it is the valid token for your API.

Regards,
Uday Kilambi

@uday_kilambiCTS I haven’t try this before can you help with these

Can i store the access token in conncector attribute and use at request body. $application.apiToken_CA$

@Santhakumar you can also store the access token in the OOTB attribute called accesstoken and refer in other HTTP operations with $application.accesstoken$

Hi team,
I have resolved this issue by creating webservice AfterOperation Rule for Custom Authentication operation and map the custom schema attribute in the rule.

After that i have used the variable $application.apiToken_CA$ inside body for other operations.
Thanks @uday_kilambiCTS @Abhinov7 @udayputta for your inputs

Hi @Santhakumar, can you please share that rule code?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.