public void WhenGettingDocumentItValidatesParameters() { AssertThrows <ArgumentNullException>(() => XrdDocument.GetFromUrl((string)null), ex => ex.ParamName == "url"); AssertThrows <ArgumentNullException>(() => XrdDocument.GetFromUrl((Uri)null), ex => ex.ParamName == "url"); }
private XrdLink GetLRDDLink(XrdDocument hostMeta) { XrdLink LRDDLink = hostMeta.Links.Where(l => l.Rel == "lrdd").FirstOrDefault(); if (LRDDLink == null) throw new MissingResourceException(string.Format("No 'lrdd' link found in host-meta file for host {0}.", HostName)); return LRDDLink; }
public void CanMakeWebFingerRequest() { string email = "someuser@" + TestHostname; WebFingerRequest request = new WebFingerRequest(email); XrdDocument document = request.GetAccountDocument(); Assert.AreEqual("http://got.it/acct:" + email, document.Aliases[0]); }
private XrdLink GetLRDDLink(XrdDocument hostMeta) { XrdLink LRDDLink = hostMeta.Links.Where(l => l.Rel == "lrdd").FirstOrDefault(); if (LRDDLink == null) { throw new MissingResourceException(string.Format("No 'lrdd' link found in host-meta file for host {0}.", HostName)); } return(LRDDLink); }
public XrdDocument GetAccountDocument() { XrdDocument hostMeta = GetHostMeta(); XrdLink LRDDLink = GetLRDDLink(hostMeta); string emailUrl = "acct:" + EMail; string fingerUrl = LRDDLink.Template.Replace("{uri}", HttpUtility.UrlEncode(emailUrl)); XrdDocument accountDocument = XrdDocument.GetFromUrl(fingerUrl); return(accountDocument); }
public void CanGetAndParseXrdDocument() { XrdDocument doc = XrdDocument.GetFromUrl(Utility.GetTestUri("xrdexamples/index")); Assert.IsNotNull(doc); Assert.AreEqual("testserver.xyperico.dk", doc.Subject); XrdProperty p1 = doc.Properties.First(); Assert.AreEqual("http://test", p1.Type); Assert.AreEqual("Blah", p1.Value); XrdLink vCard = doc.Links.Where(l => l.Rel == "http://microformats/vCard").First(); Assert.AreEqual("http://test/vCard", vCard.HRef); Assert.AreEqual("Host vCard", vCard.Title); XrdLink describedBy = doc.Links.Where(l => l.Rel == "lrdd").First(); Assert.AreEqual("http://test?uri={uri}", describedBy.Template); Assert.AreEqual("Resource Template", describedBy.Title); }
public override byte[] Handle(string path, Stream request, OSHttpRequest httpRequest, OSHttpResponse httpResponse) { Uri serviceUrl = CableBeachServerState.ServiceUrl; // Create an XRD document describing the service endpoints of this server XrdDocument xrd = new XrdDocument(serviceUrl.ToString()); xrd.Types.Add(CableBeachServices.ASSETS); xrd.Types.Add(CableBeachServices.FILESYSTEM); xrd.Links.Add(new XrdLink(new Uri(CableBeachServices.SEED_CAPABILITY), "application/json", new XrdUri(new Uri(serviceUrl, "/request_capabilities")))); xrd.Links.Add(new XrdLink(new Uri(CableBeachServices.OAUTH_INITIATE), null, new XrdUri(new Uri(serviceUrl, "/oauth/get_request_token")))); xrd.Links.Add(new XrdLink(new Uri(CableBeachServices.OAUTH_AUTHORIZE), null, new XrdUri(new Uri(serviceUrl, "/oauth/authorize_token")))); xrd.Links.Add(new XrdLink(new Uri(CableBeachServices.OAUTH_TOKEN), null, new XrdUri(new Uri(serviceUrl, "/oauth/get_access_token")))); httpResponse.ContentType = "application/xrd+xml"; return Encoding.UTF8.GetBytes(XrdParser.WriteXrd(xrd)); }
public void WhenGettingUnknownDocumentItThrows() { AssertThrows <WebException>(() => XrdDocument.GetFromUrl(Utility.GetTestUri("unknown"))); }
/// <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"); } }