June 22, 2023

AutoHotkey Basic Authentification for REST API e.g. Jira

I have stumbled upon an issue in the b64 encoding function that broke the Basic Authentication when using a longer password e.g. API token.
I share in this post how I do REST API calls with a Basic Authentication example for Jira including the fix for this issue.

b64 Encoding

For a Basic Authentication you need to encode as binary64 the string passed in the Request Header. 

I had a bug in the encoding function I was using. 
(This was triggering an error "setRequestHeader 0x80070057 - The parameter is incorrect." because the encoded string contained line breaks)
I have found the fix in this blog forum Base64 encoder/decoder for Binary data - AutoHotkey Community

The fix is also available in my repo here: https://github.com/tdalon/ahk/blob/main/Lib/b64Encode.ahk 

Basic Auth for Jira

I use to configure the API token for the Jira authentication in an INI File with following Json structure:

[Jira]

JiraAuth=[{"url":"<YourJiraUrl>","username":"<YourJiraEmail>","apitoken":"<YourApitoken>"}]

The function to create the Basic Authentication String looks like this:

API Requests

Doing REST API Calls can be then done as shown in following functions:

See also

Base64 encoder/decoder for Binary data - AutoHotkey Community

No comments:

Post a Comment