[Progress Communities] [Progress OpenEdge ABL] Forum Post: RE: Redirect to Page to re-authenticate from Widget Controller

  • Thread starter cschnick@premier-us.net
  • Start date
Status
Not open for further replies.
C

cschnick@premier-us.net

Guest
We have resolved our situation by taking a slightly different approach. We added a method to the controller that simply checks if the user is still authenticated and returns a True or a False to the JavaScript request. On the success side of the request, we determine whether a true or false was returned and act accordingly. If true, we get the data that was needed as was being returned by the original controller action. If false is returned, from the JavaScript, we simply set the document. location to the page that is hosting the custom control(s) which require(s) authentication. Since the user is not authenticated at this point, the login process is invoked automatically with a response redirect back to the page we specified as the document.location hosting the controls. The Controller method is something like... readonly Telerik.Sitefinity.Security.SitefinityIdentity LoggedInUser = ClaimsManager.GetCurrentIdentity(); [HttpGet, Route("web-interface/userIsAuthenticated")] public JsonResult ChkUserIsAuthenticated([DataSourceRequest] DataSourceRequest request) { var userIsAuthenticated = new UserIsAuthenticated(); if ((LoggedInUser.IsAuthenticated) && (LoggedInUser.UserId != Guid.Parse("00000000-0000-0000-0000-000000000000"))) { userIsAuthenticated.IsAuthenticated = true; } return Json(JsonConvert.SerializeObject(userIsAuthenticated);, JsonRequestBehavior.AllowGet); } The object returned is defined as.... public class UserIsAuthenticated { public bool IsAuthenticated { get; set; } public UserIsAuthenticated() { IsAuthenticated = false; } } The JavaScript to call it and handle the response is something like... function CheckAuthenticated() { // We have to validate that the user is still authenticated before we refresh the data. // The asynchronous nature of all this means that the call to check authentication then has // handle what to do if the user is or is not authenticated on a success. In this case the // success scenario is a call to another method var url = '@Url.Content("/web-interface/UserIsAuthenticated")'; $.ajax({ type: "GET", url: url, contentType: "application/json", dataType: "json" }).done(function (response) { HandleIsAuthenticated(response) }).fail(function (response) { console.log('Error: ' + JSON.stringify(response)); }); } function HandleIsAuthenticated(data) { var UserIsAuthenticated = JSON.parse(data); var userIsAuthenticated = UserIsAuthenticated.IsAuthenticated; if (userIsAuthenticated) { var someKeyValue= $("#someControl").data("kendoMultiSelect"); //Get the Data for the custom control GetData(someKeyValue.value); } else { document.location = "/myPageRoot/myPage"; } }

Continue reading...
 
Status
Not open for further replies.
Top