How to get the user's credentials in a gadget?
Finesse gadgets can obtain the same credentials that were entered upon login to the Finesse Agent Desktop. Once the user is logged in to the desktop, all gadgets (whether it is a stock gadget or a third-party custom gadget) have access to the credentials that were used to log in.
To obtain the username/password, do the following:
1. Get the authorization string from the configuration object. This authorization string is the base64 encoded "id:password" string used for authentication.
var auth = finesse.gadget.Config.authorization;
2. Use the Finesse JavaScript library's getCredentials() utility function to decode the authorization string into an object of agentId and password format.
var credentials = _util.getCredentials(auth);
3. Get the agentId and password from the object
var agentId = credentials.id;
var password = credentials.password;
So, if you put it all together, it will look like:
var auth = finesse.gadget.Config.authorization;
var credentials = _util.getCredentials(auth);
var agentId = credentials.id;
var password = credentials.password;
If you need the credentials for a REST API that uses BASIC Auth, you can take a shortcut and get it directly via the Finesse JavaScript library's utility function
var basicAuth = finesse.utilities.Utilities.getAuthHeaderString(finesse.gadget.Config);
Comments
0 comments
Please sign in to leave a comment.