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.
Html-bobswift |
---|
<div>
<pre id="code-block">
<code>your code here</code>
</pre>
<button onclick="copyToClipboard()">Copy to Clipboard</button>
</div>
<script>
function copyToClipboard() {
var code = document.getElementById("code-block").innerText;
navigator.clipboard.writeText(code).then(function() {
alert("Copied to clipboard");
}, function(err) {
console.error("Error copying to clipboard: ", err);
});
}
</script>
|
Token Generation Code
Token Generation Code
Advancedcodeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
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())
| ||||||
Advancedcodeblock | ||||||
| ||||||
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 = .addHeader("Accept", "http://localhost:8080/yellowfinHead"; application/vnd.yellowfin.api-v1+json") String restUsername = "admin@yellowfin.com.au"; String restPassword = "test"; .addHeader("Content-Type", "application/json") Content c = Request.postbodyString(host + "/api/refresh-tokens") "{ \"userName\": \""+ restUsername + "\",\"password\": \""+ restPassword + "\"}", null) .addHeader("Authorization", "YELLOWFIN ts=" + System.currentTimeMillis() + " , nonce=" + new Random.execute().nextLongreturnContent()); JsonObject jsonObject = .addHeader("Accept", "application/vnd.yellowfin.api-v1+json") new JsonParser().parse(c.asString()).getAsJsonObject(); JsonElement accessToken .addHeader("Content-Type", "application/json") = jsonObject.getAsJsonObject("_embedded").getAsJsonObject("accessToken").get("securityToken"); if (accessToken!=null) { .bodyString("{ \"userName\": \""+ restUsername + "\",\"password\": \""+ restPassword + "\"}", null) System.out.println("Access Token: " + accessToken); } else { System.execute()out.returnContent(println("Token not retrieved"); } JsonObject} } |
Advancedcodeblock | ||||||
---|---|---|---|---|---|---|
| ||||||
ct 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.
...