Using Authentication tokens to authenticate a user in a 3-tier environment

  • Updated

This is an example on how to authenticate users to leverage the Ektron APIs in a 3-tier environment. This is also the same process to leverage the API's in a console application as well as in MVC.

This example demonstrates how to request the authentication token of a user and pass it in to the Content Manager.GetList.

 

//Here we are calling the user object to allow us to use the authenticate method to pass the user data in.
Ektron.Cms.Framework.User.UserManager _userManager = new Ektron.Cms.Framework.User.UserManager();

//In this example we are passing the user name and password into string to be called at a later point.
string UserName = "Admin";
string Password = "Admin123";

//Next we authenticate the user based on username and password and pass it into a string value to be called later
string authToken = _userManager.Authenticate(UserName, Password);

//Here we are calling the Content Manager Object
Ektron.Cms.Framework.Content.ContentManager _contentManager = new Ektron.Cms.Framework.Content.ContentManager();

//Next we use the content manager and request the authentication token data we passed in the authToken string we created eariler
_contentManager.RequestInformation.AuthenticationToken = authToken;

//Next we chose how we retrieve the content based on our critiera filter, in this case the content id
var _criteria = new Ektron.Cms.Content.ContentCriteria();//get Criteria
_criteria.AddFilter(Ektron.Cms.Common.ContentProperty.Id, Ektron.Cms.Common.CriteriaFilterOperator.EqualTo, 30);
//Finally we return are items using the get list.
var _getList = _contentManager.GetList(_criteria);