internal static User GetWhoAmI(IEnumerable <FluxCookie> cookies, SDKMetadata sdkMetadata) { if (cookies == null) { return(null); } var authCookie = cookies.FirstOrDefault(el => el.CookieName == FluxApiData.CookiesAuthName); if (authCookie == null) { return(null); } User user = null; var request = HttpWebClientHelper.CreateRequest(sdkMetadata, FluxApiData.WhoAmIUrl, cookies.ToList()); request.Method = "GET"; using (var response = HttpWebClientHelper.GetResponse(request)) { user = DataSerializer.Deserialize <User>(StreamUtils.GetDecompressedResponseStream(response)); } user.SdkMetadata = sdkMetadata; user.Cookies = cookies.ToList(); return(user); }
public Token(string clientSecret, SDKMetadata sdkMetadata) { this.sdkMetadata = sdkMetadata; this.clientSecret = clientSecret; stateId = Guid.NewGuid(); nonceId = Guid.NewGuid(); }
public static HttpWebRequest CreateRequest(SDKMetadata sdkMetadata, string relativeUrl, List <FluxCookie> cookies) { log.Info("HttpWebRequest creation: {0}", relativeUrl); var requestUri = new Uri(sdkMetadata.BaseUri, relativeUrl); var request = (HttpWebRequest)WebRequest.Create(requestUri); request.ContentType = "application/x-www-form-urlencoded"; request.Accept = "application/json, application/xml, text/json, text/x-json, text/javascript, text/xml"; request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; //adding headers foreach (var data in sdkMetadata.FluxHeaders) { request.Headers.Add(data.Key, data.Value); } request.CookieContainer = new CookieContainer(); //adding user cookies if (cookies != null) { foreach (var cookie in cookies) { request.CookieContainer.Add(new Cookie(cookie.CookieName, cookie.CookieValue) { Domain = cookie.CookieDomain }); } //adding user-specified flux request token var authToken = cookies.First(el => el.CookieName == FluxApiData.CookiesTokenName); if (authToken != null) { request.Headers.Add(FluxApiData.HeadersRequestToken, authToken.CookieValue); } } return(request); }
internal void LoginViaOIC(string clientSecret, SDKMetadata sdkMetadata) { try { token = new Token(clientSecret, sdkMetadata); //get default browser defaultBrowser = new Browser(); defaultBrowser.OpenLinkInNewWindow(token.GetAuthorizationUrl()); //init http listener var listener = new HttpListener(); listener.Prefixes.Add(token.RedirectUrl); listener.Start(); //start waiting for requests listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener); } catch (Exception ex) { log.Error(ex); throw new Exceptions.InternalSDKException(ex.Message); } }