The user profile API provides the ability to interact with the User Content section of User Generated Content without having to custom code standard usage scenarios. The user profile API provides simple authentication, authentication validation and password reset.
The API is available in the WCF API and REST API.
Methods
API Samples
JavaScript API
The JavaScript User Profile API allows users to perform authentication, authentication validation as well as some basic profile related functions all through JavaScript.
JavaScript is highly recommended over using the .NET API for performance reasons.
var cookieName = Agility.UGC.API.GetAuthCookieName();
Agility.UGC.API.SetAuthCookieName(cookieName)
This method lets you set a custom Cookie name to store the authentication token into when the Authenticate method is called.
var cookieName = Agility.UGC.API.SetAuthCookieName("MyAuthCookieName");
Agility.UGC.API.Logout(websiteUserTypeName)
This method will clear your current authentication cookie that the user is currently logged in as. You must pass the websiteUserTypeName in case there are multiple authentication points (User Types) within your system.
Agility.UGC.API.Logout("Profile");
This method is used to authenticate a user against a specific website user type within the UGC system. An authentication token will be generated if successful and will set the authentication cookie defined by Agility.UGC.API.GetAuthCookieName();
Agility.UGC.API.Authenticate("Profile", "Username", "Password", true, function(data){ if(data.ResponseType == Agility.UGC.API.ResponseType.OK){ alert("Login Successful! Your Authentication Token is: " + data.ResponseData); } });
Agility.UGC.API.IsAuthenticated(websiteUserTypeName, callback)
This method will return a fully qualified Authentication Object which can be used to re-initialize the UGC API with the user's unique profile ID and hash code. This is important as updates to profile related data can only be done if authenticated as an Administrator or the user who owns the profile record.
Agility.UGC.API.IsAuthenticated("Profile", function(data){ if(data.ResponseType == Agiltity.UGC.API.ResponseType.OK){ //User is authenticated.. and API access data has been refreshed to use the currently logged in users credentials. } });
var currentPassword = "myCurrentPass"; var newPassword = "myNewPass"; Agility.UGC.API.IsAuthenticated("Profile", function(data){ if(data.ResponseType == Agility.UGC.API.ResponseType.OK){ Agility.UGC.API.ChangePassword(currentPassword, newPassword, function(cpData){ if(cpData.ResponseType == Agility.UGC.API.ResponseType.OK){ alert("Your password has been updated."); } }); } });
Agility.UGC.API.RetrievePassword("Profile", "MyLoginName", function(data){ if(data.ResponseType == Agility.UGC.API.ResponseType.OK){ alert("Your password has been sent to your email"); } });
.NET API
Below are example usages of the User Profile API using the WCF API.
Authenticate(DataServiceAuthorization auth, string profileTypeName, string login, string password)
using (Agility_UGC_API_WCFClient client = DataServiceUtil.APIClient) { DataServiceAuthorization auth = UGCAPIUtil.GetDataServiceAuthorization(-1); string AuthenticationToken = client.Authenticate(auth, "Profile", "miskiw", "Password"); if(AuthenticationToken!=null){ //Authentication Successful PerformLoginFunction(AuthenticationToken); } }
IsAuthenticated(DataServiceAuthorization auth, string authenticationToken, string profileRecordType)
public bool IsUserAuthenticated() { string websiteUserTypeName = "Profile"; string cookieName = string.Format("UGC_AUTH_{0}{1}", UGCAPIUtil.Agility_API_Key, websiteUserTypeName); HttpCookie authenticationCookie = Request.Cookies[cookieName]; if (authenticationCookie == null) return false; string token = HttpUtility.UrlDecode(authenticationCookie.Value); using (Agility_UGC_API_WCFClient client = UGCAPIUtil.APIClient) { DataServiceAuthorization auth = UGCAPIUtil.GetDataServiceAuthorization(-1); var auth2 = client.IsAuthenticated(auth, token, websiteUserTypeName); if (auth2 != null && auth2.ProfileRecordID > 0) { //Is Authenticated and has a valid auth object return true; } } return false; }
ChangePassword(DataServiceAuthorization auth, int profileRecordID, string currentPassword, string newPassword)
using (Agility_UGC_API_WCFClient client = DataServiceUtil.APIClient) { DataServiceAuthorization auth = UGCAPIUtil.GetDataServiceAuthorization(-1); bool success= client.ChangePassword(auth, profileRecordID, currentPassword, newPassword); if(success){ ///Password changed successfully } }
RetrievePassword(DataServiceAuthorization auth, string profileTypeName, string login)
using (Agility_UGC_API_WCFClient client = DataServiceUtil.APIClient) { DataServiceAuthorization auth = UGCAPIUtil.GetDataServiceAuthorization(-1); bool success= client.RetrievePassword(auth, "Profile", "miskiw"); if(success){ ///Password was successfully emailed to the user } }
Comments
Please sign in to leave a comment.