Example #1
0
        public void RequestToken()
        {
            TokenMutex.WaitOne();
            if (CurrentToken == null)
            {
                Console.WriteLine("Requesting Token");
                RequestNumberList[RemoteServerGroup.Instance.NodeAddress]++;
                while (CurrentToken == null)
                {
                    var rsg = RemoteServerGroup.Instance;
                    var msg = new Message
                    {
                        Data          = RequestNumberList[RemoteServerGroup.Instance.NodeAddress].ToString(),
                        MonitorId     = Id,
                        MsgType       = MessageType.TokenRequest,
                        SendingServer = rsg.NodeAddress
                    };

                    foreach (var remoteAddress in rsg.RemoteAddressesList)
                    {
                        var remoteDispatch = new RemoteDispatch(msg, remoteAddress);
                        rsg.SendQueue.Add(remoteDispatch);
                    }

                    TokenMutex.ReleaseMutex();
                    CurrentToken = ReceivedToken.Take();
                    TokenMutex.WaitOne();
                }
            }
        }
        public async Task <ReceivedToken> Authorize(string id, string secret)
        {
            var url        = "https://id.adform.com/sts/connect/token";
            var httpClient = _clientFactory.CreateClient();

            var content = new FormUrlEncodedContent(new[]
            {
                new KeyValuePair <string, string>("grant_type", "client_credentials"),
                new KeyValuePair <string, string>("client_id", id),
                new KeyValuePair <string, string>("client_secret", secret),
                new KeyValuePair <string, string>("scope", "https://api.adform.com/scope/eapi")
            });

            var requestResult = httpClient.PostAsync(url, content);

            string jsonString = await requestResult.Result.Content.ReadAsStringAsync();

            ReceivedToken result = JsonConvert.DeserializeObject <ReceivedToken>(jsonString);

            return(result);
        }
Example #3
0
    private void Process(HttpListenerContext context)
    {
        string filename  = context.Request.Url.ToString();
        string sessionid = "";

        if (!string.IsNullOrEmpty(filename))
        {
            if (filename.Contains(tokenKey))
            {
                WriteFile(LixHueSub.Properties.Resources.success, context);
                Stop();

                sessionid = filename.Substring(filename.IndexOf(tokenKey) + tokenKey.Length);

                ReceivedToken?.Invoke(sessionid);
            }
            else
            {
                WriteFile(LixHueSub.Properties.Resources.redirect, context);
            }
        }
    }