Пример #1
0
        public ActionResult StartOAuthLogin(TestEnvironmentModel model)
        {
            if (model != null)
            {
                this.Response.SetCookie(new HttpCookie("environment", JsonConvert.SerializeObject(model)));
            }

            var stateKey = Guid.NewGuid().ToString("N");

            this.Session.Add(stateKey, model);
            var parameters = HttpUtility.ParseQueryString(string.Empty);

            parameters.Add("state", stateKey);

            var callBackUri = this.GetCallBackUrl();

            parameters.Add("redirect_uri", callBackUri);
            parameters.Add("scope", model.Scope);
            parameters.Add("client_id", model.ClientId);
            parameters.Add("response_type", "authorization_code");
            parameters.Add("claimed_account_id", model.AccountId.ToString());

            var uri = new UriBuilder(model.AuthFormUrl);

            uri.Query = parameters.ToString();
            return(this.Redirect(uri.ToString()));
        }
        static void Main(string[] args)
        {
            TestEnvironmentModel te = new TestEnvironmentModel();

            te.addNode("ServerHost");
            te.addNode("ClientHost");

            string[] argus1 = {"8001", "Patrick"};
            string[] argus2 = {"8002", "Walter"};
            string[] argus3 = { "8003", "Maurice" };
            string[] argus4 = { "8000", "Asim" };

            te.addProcess("ClientTest.exe", "ClientHost", 8000, ".\\", argus1);
            te.addProcess("ClientTest.exe", "ClientHost", 8001, ".\\", argus2);
            te.addProcess("ClientTest.exe", "ClientHost", 8002, ".\\", argus3);
            te.addProcess("ClientTest.exe", "ClientHost", 8003, ".\\", argus4);

            DistributedProcessModel tmp = te.getProcess("ClientHost", "ClientTest.exe", 8000);
            te.setDelay(tmp, 3000);
            te.enableDelay(tmp);

            te.startProcess("ClientHost", 8000, "ClientTest.exe");
            te.startProcess("ClientHost", 8001, "ClientTest.exe");
            te.startProcess("ClientHost", 8002, "ClientTest.exe");
            te.startProcess("ClientHost", 8003, "ClientTest.exe");
        }
Пример #3
0
        private string GetContactInfo(string token, TestEnvironmentModel model)
        {
            var url         = string.Format("{0}/v2/accounts/{1}/contacts/me", model.PublicApiUrl, model.AccountId);
            var contactInfo = System.Net.WebRequest.Create(url)
                              .SetBearerAuth(token)
                              .GetResponse()
                              .DownloadJsonObject <dynamic>();

            return(contactInfo.Email);
        }
Пример #4
0
        private string GetToken(string code, TestEnvironmentModel model)
        {
            var redirectUrl = this.GetCallBackUrl();
            // init
            var data = string.Format("grant_type={0}&code={1}&client_id={2}&redirect_uri={3}&scope={4}", "authorization_code", code, model.ClientId, redirectUrl, model.Scope);

            // execute
            var response = System.Net.WebRequest.Create(model.OAuthTokenEndpoint)
                           .SetBasicAuth(model.ClientId, model.ClientSecret)
                           .SetData(data)
                           .GetResponse();

            var tokenData = response.DownloadJsonObject <dynamic>();
            var token     = tokenData.access_token.ToString();

            return(token as string);
        }
Пример #5
0
        private string GetLogoutNonce(string token, TestEnvironmentModel model, string redirectUrl)
        {
            var response = System.Net.WebRequest.Create(model.LogoutNonceUrl)
                           .SetBasicAuth(model.ClientId, model.ClientSecret)
                           .SetJsonData(JsonConvert.SerializeObject(
                                            new
            {
                token,
                email = this.User.Identity.Name,
                redirectUrl
            }
                                            ))
                           .GetResponse();

            var nonce = response.DownloadJsonObject <dynamic>().nonce.ToString();

            return(nonce as string);
        }
Пример #6
0
        public ActionResult Index()
        {
            var model = new TestEnvironmentModel()
            {
                AccountId             = 1,
                ClientId              = "set client id from settings / security / authorized applications",
                ClientSecret          = "set client secret from settings / security / authorized applications",
                OAuthServiceUrl       = "https://oauth.wildapricot.org",
                PublicApiUrl          = "https://api.wildapricot.org",
                AssociationWebSiteUrl = "https://yourassociation.wildapricot.org",
                Scope = "auto"
            };

            var modelCookie = this.Request.Cookies["environment"];

            if (modelCookie != null)
            {
                model = JsonConvert.DeserializeObject <TestEnvironmentModel>(modelCookie.Value);
            }

            return(this.View(model));
        }