talend requesting Oath bearer token using basic authentication x-www-form-urlencoded

So this turned out harder than I imagined it to be but eventually with the combination of many forum posts I was able to get it to work.

Basically Base64 encode your username password for use in Basic authentication. Prepend “Basic ” (don’t forget the space) as the Authorization

I was passing Content-Type “application/x-www-form-urlencoded” and for that it means you need to use the format like this something=something&anotherthing=123 (helpful post)

I also randomly learned that postman can generate code! How cool is that!

The post that was the most useful was

https://community.talend.com/s/feed/0D53p00007vCsxdCAC?language=en_US

It has a couple of typos that can throw you though!

First, create a tJava object. Go to the advanced settings and add the following import:

import com.sun.jersey.core.util.Base64;

In the basic settings, add the following code:

String pair = "yourusername:yourpassword";
byte[] encodedBytes = Base64.encode(pair.getBytes());
globalMap.put("authorization", new String(encodedBytes));
System.out.println(globalMap.get("authorization"));

Now connect the tJava to the tRest using the OnComponentOk trigger.
In the tRest, add a HTTP Header called “Authorization” and set it to “Basic ” + (String)globalMap.get(“authorization”):

In the original article there are some typo’s so here is a working screen shot

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s