Advanced Use of Custom Access Token in HTTP Requests

26 October 2023
KingswaySoft Team

Initiating and creating a custom API request can be a complex task in an ETL process, since it often involves various configurations and parameters, such as query string parameters, request headers, and request body (if applicable). This becomes especially challenging when the process involves the extraction of authorization tokens from an initial authentication request and injecting them into subsequent HTTP requests. KingswaySoft provides an optimum solution through its SSIS Productivity Pack product, which greatly simplifies and streamlines this process. In this blog post, we will be discussing one such case, where the content of a specific session cookie needs to be drilled down and used in the request headers. Shown below are the components that we will use in this demonstration:

As mentioned, the above components are available as a part of KingswaySoft's SSIS Productivity Pack.

Understanding the Custom Access Token

Custom access tokens are typically used to obtain authorization tokens from a server, which then can be used to access resources on the server after presenting the token to it. Obtaining authorization tokens can be generally achieved by issuing a CURL command that contains the necessary information to send the authentication request to the server. This process is supported by one of the authentication modes offered in the HTTP Connection Manager, in SSIS Productivity Pack, called Custom Token.

Custom Token Authentication Mode.png

Once you have selected the Custom Token option in the HTTP Connection Manager, you can either pull the CURL command from a file or enter it manually, as illustrated below. More details on how to work with this mode can be found in our blog post on Working with Custom Authentication Token in KingswaySoft HTTP Connection Manager.

Test Custom Token.png

As illustrated above, we are extracting the "Set-Cookie" header from the received response, which contains some required authentication information that can be used for subsequent requests for authentication purposes. With the configuration shown above, the "Set-Cookie" header received from the response will be saved in a variable called @Connection[AccessToken] for later use. For reference purposes, the content of the "Set-Cookie" might look like this:

AWSALB=XXXXXXXSH03CJX01YxvTp5N5pXXXXXXXXJX01YxvTp5N5p9NHIiSpBCNj6Wne8I457aAz1; Expires=Wed, 27 Sep 2023 21:11:35 GMT; Path=/,AWSALBCORS=XXXXXX010Fu2T70hOUPuXXXXXXCNj6Wne8I457aAz1; Expires=Wed, 27 Sep 2023 21:11:35 GMT; Path=/; SameSite=None; Secure,JSESSIONID=XXXXXX2FA30XXXXXC93F5F; Path=/api; Secure; HttpOnly,model.sessionId=XXXXXD4F53BFXXXXXX71B8; Path=/; Secure; HttpOnly

Our objective here is to pick up a couple of values from the "Set-Cookie" header and place them in the headers of subsequent HTTP requests.

Using the Access Token within JSON components

As mentioned, we will use the above-extracted token in a subsequent component. For this, we will be working with the JSON Source Component. We need to drag and drop a JSON Source Component and choose the Connection Manager that was just configured. In the Request headers section, add the Header name, and then click on the fx button to open the SSIS expressions editor. Switch to Expression mode. Now, here, we can use the below expression that utilizes the GetTokenAtPosition().

Expression Editor.png

As illustrated above, we are extracting the JSESSIONID value from the authentication response header.

Request header expression.png

Once we have completed the expression for the value extraction, we can save it. We should now be able to find the parameters as shown below. Note that the parsed value will not show the design time but only at runtime.

After everything is ready, we can click on the Preview button, and we shall see that the value for JSESSIONID is assigned to the request header as expected. This is the result of the expression parsing out the value from the Set-Cookie token, which was previously saved in the @Connection[AccessToken].

Request preview.png

Similarly, you could add more parameters, using similar expressions to get other headers as needed.

Multiple parameters.png

Conclusion

Much like the use case discussed above, the Custom Access Token method can provide a very flexible approach to working with dynamic headers and body values. In this way, the process of building a custom request becomes easier and more intuitive.

We hope this has helped!

Archive

November 2024 3 October 2024 1 September 2024 1 August 2024 2 July 2024 1 June 2024 1 May 2024 1 April 2024 2 March 2024 2 February 2024 2 January 2024 2 December 2023 1 November 2023 1 October 2023 2 August 2023 1 July 2023 2 June 2023 1 May 2023 2 April 2023 1 March 2023 1 February 2023 1 January 2023 2 December 2022 1 November 2022 2 October 2022 2 September 2022 2 August 2022 2 July 2022 3 June 2022 2 May 2022 2 April 2022 3 March 2022 2 February 2022 1 January 2022 2 December 2021 1 October 2021 1 September 2021 2 August 2021 2 July 2021 2 June 2021 1 May 2021 1 April 2021 2 March 2021 2 February 2021 2 January 2021 2 December 2020 2 November 2020 4 October 2020 1 September 2020 3 August 2020 2 July 2020 1 June 2020 2 May 2020 1 April 2020 1 March 2020 1 February 2020 1 January 2020 1 December 2019 1 November 2019 1 October 2019 1 May 2019 1 February 2019 1 December 2018 2 November 2018 1 October 2018 4 September 2018 1 August 2018 1 July 2018 1 June 2018 3 April 2018 3 March 2018 3 February 2018 3 January 2018 2 December 2017 1 April 2017 1 March 2017 7 December 2016 1 November 2016 2 October 2016 1 September 2016 4 August 2016 1 June 2016 1 May 2016 3 April 2016 1 August 2015 1 April 2015 10 August 2014 1 July 2014 1 June 2014 2 May 2014 2 February 2014 1 January 2014 2 October 2013 1 September 2013 2 August 2013 2 June 2013 5 May 2013 2 March 2013 1 February 2013 1 January 2013 1 December 2012 2 November 2012 2 September 2012 2 July 2012 1 May 2012 3 April 2012 2 March 2012 2 January 2012 1

Tags