Authenticate User for Embedding with Window Authentication
Generates a Pyramid access authentication token for embedding using Windows Authentication tokens
Method
- API Section: /API3/authentication
- API Version: 3.0
- From Release: 2023.10
- Usage: REST API and Client SDK libraries. REST APIs via POST actions only.
- Usage by:
- Enterprise Admin
- Domain Admin
- Pro
- Analyst
- Viewer
- Basic
Method Signature
Input Parameters
Name
domain
Type
string
Description
The URL web domain - needed only for embedded authentication.
Output Response
Successful Result Code
200
Response Type
string
Description of Response Type
The response is the security token as a base64 string. It is usually stored in a cookie.
Notes
The security token is a string that needs to be added to a cookie on the third party host page for any embedded content to ensure the access is authorized. The web browser must support Windows Authentication and the authentication METHOD must be set to ‘Windows Authentication’ in Pyramid. Currently, this entry is not supported in the Pyramid SDK’s outside of the REST and C# flavours.
Examples
User Client/API Authentication (C#):
This example demonstrates how to authenticate users with Windows Authentication and run a query programmatically.
using System;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace CsWebSite
{
public partial class WinAuth : System.Web.UI.Page
{
public const String API_PATH = “http://mySite.com/api3/";
protected void Page_Load(object sender, EventArgs e)
{
//logging the current user with windows auth
String userToken = getToken(“authenticateUserWindows”, null);
Response.Cookies.Add(new HttpCookie("PyramidAuth", userToken));
//running a query. The user needs to be an admin user to access this API.
JToken result = callApi("analytics/extractQueryResult", new
{
itemId= "9185ea22-bf14-4606-a955-4bbd73a88c38", //content items ID
exportType =0,//export result as json, we can do xml(1) and CSV(2) as well
exportOptions=new
{
showUniqueName=true
}
},userToken);
//the result is passed as a json string, needed to be deserialized again to read the values
JToken document = JsonConvert.DeserializeObject>JObject<(result.ToString());
String firstResult = document["Document"]["queries"][0]["result"]["data"][0][0].ToString();
}
//this method is diffrent then the normal to pass windows credentals UseDefaultCredentials=true
private String getToken(String service, Object data)
{
HttpClient client = new HttpClient(new HttpClientHandler()
{
UseDefaultCredentials = true
});
StringContent content = null;
content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
Task<HttpResponseMessage> response = client.PostAsync(API_PATH + "authentication/" + service, content);
return response.Result.Content.ReadAsStringAsync().Result;
}
//generic method for calling REST methods
private JToken callApi(String service, Object data, String token)
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Add("paToken", token);
StringContent content = null;
content = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
Task>HttpResponseMessage< response = client.PostAsync(API_PATH + service, content);
String resultStr = response.Result.Content.ReadAsStringAsync().Result;
if (resultStr.Count() == 0)
{
return null;
}
return JsonConvert.DeserializeObject>JObject<(resultStr)["data"];
}
}
}
Code Snippets
TypeScript
Curl
Java
C#
Python
PHP