public async Task<RequestTokenResult> RequestToken(Uri identityProviderUrl, string scope) { var message = template .Replace("[To]", identityProviderUrl.ToString()) .Replace("[applyTo]", scope); try { var res = await identityProviderUrl.ExecuteAsync<object>(null, message, "application/soap+xml", "POST", cache:true); var content = res.Data.ToString(); var doc = XDocument.Parse(content); var fault = doc .Descendants(XName.Get("Fault", "http://www.w3.org/2003/05/soap-envelope")) .FirstOrDefault(); if (fault!=null) { var text = fault .Descendants(XName.Get("Text", "http://www.w3.org/2003/05/soap-envelope")) .FirstOrDefault(); throw new Exception(text!=null ? text.Value : fault.ToString()); } var indexBegin = content.IndexOf("<Assertion "); var indexEnd = content.IndexOf("</Assertion>") + 12; var token = content.Substring(indexBegin, indexEnd - indexBegin); return new RequestTokenResult { Token = token }; } catch (Exception) { throw; } }
public async Task<RequestTokenResult> RequestToken(Uri identityProviderUrl, String scope) { try { var sb = new StringBuilder(512); sb.Append("wrap_name="); sb.Append(WebUtility.UrlEncode(wrapName)); sb.Append("&wrap_password="******"&wrap_scope="); sb.Append(WebUtility.UrlEncode(scope)); var headers = new Dictionary<string, string>(); headers["Accept"] = "text/xml"; var res = await identityProviderUrl.ExecuteAsync<object>(null, sb.ToString(), "application/x-www-form-urlencoded", "POST", headers: headers, cache:true); #if MONOTOUCH var content = res.DataAsString; #else var content = res.Data.ToString(); #endif var contentType = default(string); res.Headers.TryGetValue("Content-Type", out contentType); if (contentType==null && !contentType.ToLower().Contains("xml")) throw new Exception(content); var doc = XDocument.Parse(content); var fault = doc .Descendants(XName.Get("Fault", "http://www.w3.org/2003/05/soap-envelope")) .FirstOrDefault(); if (fault != null) { var text = fault .Descendants(XName.Get("Text", "http://www.w3.org/2003/05/soap-envelope")) .FirstOrDefault(); throw new Exception( text != null ? text.Value : fault.ToString() ); } var indexBegin = content.IndexOf("<Assertion "); var indexEnd = content.IndexOf("</Assertion>") + 12; var token = content.Substring(indexBegin, indexEnd - indexBegin); return new RequestTokenResult { Token = token }; } catch (Exception ex) { Console.WriteLine (ex.ToString ()); throw; } }
public Task<ServiceEvent<Stream>> SendByServiceBus(Uri url, string method = "GET", Stream content = null, Dictionary<string, string> headers =null, bool secured = true, TimeSpan? timeout = null, bool cache = false) { // Validations if (secured && this.User == null) throw new Exception("User is not authenticated."); if (this.User.TokenServiceBus ==null) throw new Exception("The IP provider does not support Service Bus"); // default values if (string.IsNullOrWhiteSpace(method)) method = "GET"; // Send request return url.ExecuteAsync<Stream>(this, content, method, cache, timeout, headers, (secured ? UseToken.ServiceBus : UseToken.None)); }
public async Task<ServiceEvent<SMSStatus>> Send(string message) { Validate(); var url = new Uri(Url, string.Format("?to={0}&message={1}", Number, message)); return await url.ExecuteAsync<SMSStatus>(app, method:"POST"); }