using System; using System.Web; using Telligent.Evolution.Extensibility; using Telligent.Evolution.Extensibility.Api.Entities.Version1; using Telligent.Evolution.Extensibility.Api.Version1; using Telligent.Evolution.Extensibility.Security.Version2; namespace Sample { class SampleAuthenticationPlugin : IAuthenticationPlugin { #region IPlugin Implementation public string Name { get { return "Sample Authentication Single-Sign-On Client"; } } public string Description { get { return "Sample IAuthentication plugin implementation."; } } public void Initialize() { // Leave blank if not needed. } #endregion public int? GetAuthenticatedUserId(AuthenticationOptions options) { // Check the HttpContext from the given options HttpContextBase context = options.HttpContext; if (context == null) return null; // Use the context to extract the needed information about the accessing user. // For instance, from a certain cookie... HttpCookie cookie = context.Request.Cookies["CookieName"]; if (cookie == null) return null; // or from the context ASP.net user. if (context.User == null || context.User.Identity == null || string.IsNullOrEmpty(context.User.Identity.Name)) return null; // Extract information to identify the user. // Access the User API and find the user based on the information retrieved above. var userApi = Apis.Get(); User foundUser = userApi.Get(new UsersGetOptions { Username = "username" }); if (foundUser == null) { // If the user doesn't exist, you may want to create an account // if you are trying to stay synced with another system. // If not, you can throw an exception here about the login failing. throw new Exception("Login Failed"); } // Assuming a user was found, return the id for Community to use. return foundUser.Id; } } }