cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1227
Views
25
Helpful
3
Replies

Authorization Header / Cisco Finesse - External REST API Sample Gadget

kenny.araya
Level 1
Level 1

Hello Everyone,

 

I'm using the Cisco Finesse - External REST API Sample Gadget to send credentials from Finesse to a URL in a GET request every time an agent answers a call. I am a little stuck in step 4, where the Gagdet's documentation specifies how to use the Authorization Header.

4. If the external REST API requires an authorization header, uncomment the line of code that adds the authorization to the options object. If the authorization type is Basic Auth, then you can skip to the next step.

 

Document link for reference: https://github.com/CiscoDevNet/finesse-sample-code/blob/master/ExternalRestApiSampleGadget/README.md

 

I did uncomment the line of code specified, now I am not certain how the credentials will be included in the authorization field of the options object (finesse.gadget.Config?).

 

Thanks in advance for the assistance provided on this!

KennyScreenshot 2021-11-29 at 15.22.25.png

 

3 Replies 3

Gerry O'Rourke
Spotlight
Spotlight

Kenny,

 

I believe the assumption in the example gadget if using authorization, is that the same authorization to log into Finesse is used to access the REST API.

 

If you have a look at this Link - it shows you how to get the login details / authorization of the logged in user:

https://devnetsupport.cisco.com/hc/en-us/articles/115012962388-Getting-the-user-s-credentials-in-a-gadget

 

And this is what the example gadget is doing.

If you want to send different authorization - set the header accordingly.

 

Here is some details and background on how to set basic auth.

Background

https://en.wikipedia.org/wiki/Basic_access_authentication

 

How to encode Base64-encoded ASCII

https://developer.mozilla.org/en-US/docs/Web/API/btoa

 

Example:

https://www.codegrepper.com/code-examples/javascript/basic+authentication+header+javascript

 

Regards,

Gerry

Hi Gerry,

 

Thanks for your response. You are correct, I am actually trying to send a different authorization, in this case where should I include the piece of code from https://www.codegrepper.com/code-examples/javascript/basic+authentication+header+javascript in the gadget code?

 

Thanks again,

Kenny

Hi Kenny,

 

You need to change the authorization line to something similar to the one found in your link.

 

Change:

authorization: _util.getAuthHeaderString(finesse.gadget.Config),
to
authorization: "Basic " + finesse.utilities.Utilities.b64Encode(username + ":" + password),
where the username variable is the user's username and the password variable is the user's password. Of course you should not be hardcoding this information in the JS, so you will need to retrieve this data somehow.
 
Thanx,
Denise