Page History
...
A token can be generated with the POST /api/refresh-tokens end-point.
This service initializes a security token, and the access token is also returned in the request response. The access token needs to be provided in the header for all the other REST services mentioned in this document.
Token Generation Code
Copytoclipboard |
---|
package rest.code.examples;
import java.util.Random;
import org.apache.hc.client5.http.fluent.Content;
import org.apache.hc.client5.http.fluent.Request;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
/**
* Request an access token from the Yellowfin refresh-tokens REST end-point
*/
public class GetLoginToken {
public static void main(String[] args) throws Exception {
String host = "http://localhost:8080/yellowfinHead";
String restUsername = "admin@yellowfin.com.au";
String restPassword = "test";
Content c = Request.post(host + "/api/refresh-tokens")
.addHeader("Authorization", "YELLOWFIN ts=" + System.currentTimeMillis() + " , nonce=" + new Random().nextLong())
.addHeader("Accept", "application/vnd.yellowfin.api-v1+json")
.addHeader("Content-Type", "application/json")
.bodyString("{ \"userName\": \""+ restUsername + "\",\"password\": \""+ restPassword + "\"}", null)
.execute().returnContent();
JsonObject jsonObject = new JsonParser().parse(c.asString()).getAsJsonObject();
JsonElement accessToken = jsonObject.getAsJsonObject("_embedded").getAsJsonObject("accessToken").get("securityToken");
if (accessToken!=null) {
System.out.println("Access Token: " + accessToken);
} else {
System.out.println("Token not retrieved");
}
}
} |
The following examples illustrate how to fetch an access token in various programming languages.
...