/// <summary> /// Handles all GET and POST requests for OpenID identifier pages and endpoint /// server communication /// </summary> public void Handle(string path, Stream request, Stream response, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { // Try and lookup this avatar UserProfileData profile; if (CableBeachState.TryGetProfile(httpRequest.Url, out profile)) { if (httpRequest.Url.AbsolutePath.EndsWith(";xrd")) { m_log.Debug("[CABLE BEACH IDP]: Returning XRD document for " + profile.Name); Uri identity = new Uri(httpRequest.Url.ToString().Replace(";xrd", String.Empty)); // Create an XRD document from the identity URL and filesystem (inventory) service XrdDocument xrd = new XrdDocument(identity.ToString()); xrd.Links.Add(new XrdLink(new Uri("http://specs.openid.net/auth"), null, new XrdUri(identity))); xrd.Links.Add(new XrdLink(new Uri(CableBeachServices.FILESYSTEM), "application/json", new XrdUri(CableBeachState.LoginService.m_config.InventoryUrl))); byte[] data = System.Text.Encoding.UTF8.GetBytes(XrdParser.WriteXrd(xrd)); httpResponse.ContentLength = data.Length; httpResponse.ContentType = "application/xrd+xml"; httpResponse.OutputStream.Write(data, 0, data.Length); } else { m_log.Debug("[CABLE BEACH IDP]: Returning user identity page for " + profile.Name); Uri openidServerUrl = new Uri(httpRequest.Url, "/openid/server"); Uri xrdUrl = new Uri(httpRequest.Url, "/users/" + profile.FirstName + "." + profile.SurName + ";xrd"); CableBeachState.SendProviderUserTemplate(httpResponse, profile, openidServerUrl, xrdUrl); } } else { m_log.Warn("[CABLE BEACH IDP]: Couldn't find an account for identity page " + httpRequest.Url); // Couldn't parse an avatar name, or couldn't find the avatar in the user server httpResponse.StatusCode = (int)HttpStatusCode.NotFound; OpenAuthHelper.AddToBody(httpResponse, "OpenID identity not found"); } }