cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
820
Views
15
Helpful
4
Replies

How can you encode credentials in Base64 via UCCX editor (UCCX 9.0(2) Premium)?

patriciabohn
Level 1
Level 1

We have successfully authenticated but the only way we were able to figure out how was to manually encode (see below):


java.net.URLConnection c = new java.net.URL("http://192.168.1.111/adminapi/campaign").openConnection(); 
c.setDoInput(true);
c.setRequestProperty("Authorization","Basic dWNjeGFkbWluOmlwY3NjMTI=");
c.connect();

 

Does anyone know how to complete this authentication without manually encoding?  Any help/input is appreciated!  Thanks!

4 Replies 4

Aaron Harrison
VIP Alumni
VIP Alumni

Hi

Try this:

c.setRequestProperty("Authorization","Basic " + com.sun.org.apache.xerces.internal.impl.dv.util.Base64.encode(("username" + ":" + "password").getBytes()).trim());

Swapping out "username" and "password" for better strings or variables.

I should mention that in my IDE this 'xerces' class is flagged as 'propriety, internal and may be removed from Java in a future release'... however it's still there in JDK 8 so I wouldn't sweat it too much. The other option is you'd have to load up another API or google an example of manual encoding (there are some) but this is a good one-liner.

Regards

Aaron

Please rate helpful posts..

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!

Hi,

how 'bout this:

new String(javax.xml.bind.DatatypeConverter.printBase64Binary(orig.getBytes()));

In action:

Both orig and encoded are Strings.

Tested with UCCX 8.0 (JDK 6).

G.

P.S.: Aaron. com.sun.*?! Not cool.

Thank you both for your quick reply!!  We tested both solutions and they both worked!

Hi G

Yeah, I kind of knew that... but never got round to looking up a better way :-)

+5 

Aaron

Aaron Please remember to rate helpful posts to identify useful responses, and mark 'Answered' if appropriate!
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community: