private bool HandleLiveId(string token, string host) { Tuple <bool, bool> inCache = IsInCache(host, token); if (inCache.Item1) { return(inCache.Item2); } WindowsLiveLogin wll = new WindowsLiveLogin(Constants.LiveIdappId, Constants.LiveIdappsecret, Constants.LiveIdsecurityAlgorithm, true, Constants.LiveIdpolicyURL, Constants.LiveIdreturnURL); WindowsLiveLogin.User user = wll.ProcessToken(token); if (user == null) { ThrowRejection(HttpStatusCode.Unauthorized, "Invalid user token in authorization header."); } if (DateTime.UtcNow.Subtract(user.Timestamp).TotalMilliseconds > Constants.PrivilegeLevelTokenExpiry[Constants.LiveId] * 1000) { ThrowRejection(HttpStatusCode.Unauthorized, "Expired token being presented. Token Expiry: " + Constants.PrivilegeLevelTokenExpiry[Constants.LiveId] + " seconds"); } bool retVal = IsValidAccess(host, Constants.LiveId, user.Id); UpdateCache(host, token, user.Timestamp, retVal); // *** updating cache return(retVal); }
private void LoadSettings() { Title = SiteUtils.FormatPageTitle(siteSettings, Resource.RegistrationConfirmation); winliveCookieName = "winliveid" + siteSettings.SiteId.ToInvariantString(); windowsLive = WindowsLiveHelper.GetWindowsLiveLogin(); if (windowsLive == null) { return; } string winLiveToken = CookieHelper.GetCookieValue(winliveCookieName); if (winLiveToken.Length > 0) { liveUser = windowsLive.ProcessToken(winLiveToken); } AddClassToBody("confirmregistration"); }
private void LoadSettings() { timeOffset = SiteUtils.GetUserTimeOffset(); timeZone = SiteUtils.GetUserTimeZone(); if (SiteUtils.SslIsAvailable()) { protocol = "https://"; } mojoProfileConfiguration profileConfig = mojoProfileConfiguration.GetConfig(); foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if ((propertyDefinition.RequiredForRegistration) || (propertyDefinition.ShowOnRegistration)) { requiredProfileProperties.Add(propertyDefinition); } } winliveCookieName = "winliveid" + siteSettings.SiteId.ToString(CultureInfo.InvariantCulture); windowsLive = WindowsLiveHelper.GetWindowsLiveLogin(); if (windowsLive == null) { return; } windowsLiveAppId = windowsLive.AppId; string winLiveToken = CookieHelper.GetCookieValue(winliveCookieName); if (winLiveToken.Length > 0) { liveUser = windowsLive.ProcessToken(winLiveToken); } AddClassToBody("registerwinlivepage"); }
private string GetUserName(string scheme, string stoken) { // if this is a liveID authenticated user. he must have a name associated with this token if (scheme.Equals(Constants.LiveId, StringComparison.CurrentCultureIgnoreCase)) { WindowsLiveLogin wll = new WindowsLiveLogin(Constants.LiveIdappId, Constants.LiveIdappsecret, Constants.LiveIdsecurityAlgorithm, true, Constants.LiveIdpolicyURL, Constants.LiveIdreturnURL); WindowsLiveLogin.User windowsliveiduser = wll.ProcessToken(stoken); string name = platform.GetLiveIdUserName(windowsliveiduser.Id); if (string.IsNullOrEmpty(name)) { return("unknown"); } else { return(name); } } return(scheme); }
private string HandleAddUserGuiWebPage(string stoken, Dictionary <string, string> dict) { string html = ""; try { WindowsLiveLogin wll = new WindowsLiveLogin(Constants.LiveIdappId, Constants.LiveIdappsecret, Constants.LiveIdsecurityAlgorithm, true, Constants.LiveIdpolicyURL, Constants.LiveIdreturnURL); WindowsLiveLogin.User windowsliveiduser = wll.ProcessToken(stoken); if (windowsliveiduser == null) { throw new Exception("unable to decrypt liveid token"); } else if (DateTime.UtcNow.Subtract(windowsliveiduser.Timestamp).TotalMilliseconds <= Constants.PrivilegeLevelTokenExpiry[Constants.LiveId] * 1000) { dict["liveIdUniqueUserToken"] = windowsliveiduser.Id; string redirectTo = "../" + Constants.GuiServiceSuffixWeb + "/" + GuiWebAddLiveIdUserPage; foreach (string param in dict.Keys) { redirectTo += param + "=" + dict[param] + ","; } redirectTo = redirectTo.TrimEnd(','); html += "<html> " + redirectJS + "<script type='text/javascript'>redirect(\"" + redirectTo + "\");</script>"; } else { throw new Exception("Token provided is expired."); } } catch (Exception e) { logger.Log("Unable to add user. Exception : " + e); string redirectTo = "../" + Constants.GuiServiceSuffixWeb + "/" + GuiWebAddLiveIdUserPage + "?function=message,message= User add failed! " + e.Message; html += "<html> " + redirectJS + "<script type='text/javascript'>redirect(\"" + redirectTo + "\");</script>"; } return(html); }
private void DoLogout() { SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); string winliveCookieName = "winliveid" + siteSettings.SiteId.ToString(CultureInfo.InvariantCulture); string roleCookieName = SiteUtils.GetRoleCookieName(siteSettings); HttpCookie roleCookie = new HttpCookie(roleCookieName, string.Empty); roleCookie.Expires = DateTime.Now.AddMinutes(1); roleCookie.Path = "/"; Response.Cookies.Add(roleCookie); HttpCookie displayNameCookie = new HttpCookie("DisplayName", string.Empty); displayNameCookie.Expires = DateTime.Now.AddMinutes(1); displayNameCookie.Path = "/"; Response.Cookies.Add(displayNameCookie); // apparently we need this here for folder sites using windows auth //https://www.mojoportal.com/Forums/EditPost.aspx?thread=13195&forumid=2&mid=34&pageid=5&pagenumber=1 CookieHelper.ExpireCookie("siteguid" + siteSettings.SiteGuid); bool useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false); if ((useFolderForSiteDetection) && (!WebConfigSettings.UseRelatedSiteMode)) { string cookieName = "siteguid" + siteSettings.SiteGuid.ToString(); HttpCookie siteCookie = new HttpCookie(cookieName, string.Empty); siteCookie.Expires = DateTime.Now.AddMinutes(1); siteCookie.Path = "/"; Response.Cookies.Add(siteCookie); CookieHelper.ExpireCookie("siteguid" + siteSettings.SiteGuid); } else { FormsAuthentication.SignOut(); } string winLiveToken = CookieHelper.GetCookieValue(winliveCookieName); WindowsLiveLogin.User liveUser = null; if (winLiveToken.Length > 0) { WindowsLiveLogin windowsLive = WindowsLiveHelper.GetWindowsLiveLogin(); try { liveUser = windowsLive.ProcessToken(winLiveToken); if (liveUser != null) { Response.Redirect(windowsLive.GetLogoutUrl()); Response.End(); } } catch (InvalidOperationException) { } } try { if (Session != null) { Session.Clear(); Session.Abandon(); } } catch (HttpException) { } string redirectUrl = SiteUtils.GetNavigationSiteRoot() + "/Default.aspx"; if (!siteSettings.UseSslOnAllPages) { if (redirectUrl.StartsWith("https:")) { redirectUrl = redirectUrl.Replace("https:", "http:"); } } WebUtils.SetupRedirect(this, redirectUrl); }
private void LoadSettings() { timeOffset = SiteUtils.GetUserTimeOffset(); timeZone = SiteUtils.GetUserTimeZone(); if (SiteUtils.SslIsAvailable()) protocol = "https://"; mojoProfileConfiguration profileConfig = mojoProfileConfiguration.GetConfig(); foreach (mojoProfilePropertyDefinition propertyDefinition in profileConfig.PropertyDefinitions) { if ((propertyDefinition.RequiredForRegistration)||(propertyDefinition.ShowOnRegistration)) { requiredProfileProperties.Add(propertyDefinition); } } winliveCookieName = "winliveid" + siteSettings.SiteId.ToString(CultureInfo.InvariantCulture); windowsLive = WindowsLiveHelper.GetWindowsLiveLogin(); if (windowsLive == null) { return; } windowsLiveAppId = windowsLive.AppId; string winLiveToken = CookieHelper.GetCookieValue(winliveCookieName); if (winLiveToken.Length > 0) { liveUser = windowsLive.ProcessToken(winLiveToken); } AddClassToBody("registerwinlivepage"); }
private void DoLogout() { SiteSettings siteSettings = CacheHelper.GetCurrentSiteSettings(); string winliveCookieName = "winliveid" + siteSettings.SiteId.ToString(CultureInfo.InvariantCulture); string roleCookieName = SiteUtils.GetRoleCookieName(siteSettings); HttpCookie roleCookie = new HttpCookie(roleCookieName, string.Empty); roleCookie.Expires = DateTime.Now.AddMinutes(1); roleCookie.Path = "/"; Response.Cookies.Add(roleCookie); HttpCookie displayNameCookie = new HttpCookie("DisplayName", string.Empty); displayNameCookie.Expires = DateTime.Now.AddMinutes(1); displayNameCookie.Path = "/"; Response.Cookies.Add(displayNameCookie); bool useFolderForSiteDetection = ConfigHelper.GetBoolProperty("UseFoldersInsteadOfHostnamesForMultipleSites", false); if ((useFolderForSiteDetection) && (!WebConfigSettings.UseRelatedSiteMode)) { string cookieName = "siteguid" + siteSettings.SiteGuid.ToString(); HttpCookie siteCookie = new HttpCookie(cookieName, string.Empty); siteCookie.Expires = DateTime.Now.AddMinutes(1); siteCookie.Path = "/"; Response.Cookies.Add(siteCookie); } else { FormsAuthentication.SignOut(); } string winLiveToken = CookieHelper.GetCookieValue(winliveCookieName); WindowsLiveLogin.User liveUser = null; if (winLiveToken.Length > 0) { WindowsLiveLogin windowsLive = WindowsLiveHelper.GetWindowsLiveLogin(); try { liveUser = windowsLive.ProcessToken(winLiveToken); if (liveUser != null) { Response.Redirect(windowsLive.GetLogoutUrl()); Response.End(); } } catch (InvalidOperationException) { } } try { if (Session != null) { Session.Abandon(); } } catch (HttpException) { } WebUtils.SetupRedirect(this, SiteUtils.GetNavigationSiteRoot() + "/Default.aspx"); }