Esempio n. 1
0
        /// <summary>
        /// This method should not be in production. It is solely used to preconfigure the Windows Azure Access Control Service.
        /// </summary>
        /// <returns></returns>
        public ActionResult ProvisionApplication()
        {
            string clientId     = "06B059BE-E8AF-4FD5-A784-833A988A64A0";
            string clientSecret = "AE3A7E6E-DA37-4F99-96A9-70FFCCAACDE1";
            string redirectUri  = "http://localhost:3476/Home/Connect/";

            // Register the demo client application
            try
            {
                var x = new ApplicationRegistrationService();
                x.RegisterApplication(clientId, clientSecret, redirectUri, "MyBrewRecipes");

                // Also remove the
                x.RemoveDelegation(clientId, "maartenba", "");
            }
            catch
            {
            }

            // Remove delegation for our test user
            try
            {
                var x = new ApplicationRegistrationService();
                x.RemoveDelegation(clientId, "maartenba", "");
            }
            catch
            {
            }

            return(Content("The client_id has been provisioned."));
        }
Esempio n. 2
0
        private ApplicationRegistrationService GetTestServiceWithUser(string userName)
        {
            ApplicationRegistrationService svc = GetTestService();

            SetCurrentUser(userName, svc);
            return(svc);
        }
Esempio n. 3
0
        private ApplicationRegistrationService GetTestService()
        {
            ServiceRegistry registry           = ApplicationServiceRegistryContainer.GetServiceRegistry();
            ApplicationRegistrationService svc = registry.Get <ApplicationRegistrationService>();

            registry.SetProperties(svc);
            return(svc);
        }
        public ActionResult Index(string code, string error)
        {
            string authorizeUri = "http://localhost:31875/authorize";
            string clientId     = "testclient3";
            string clientSecret = "testsecret";
            string redirectUri  = "http://localhost:31875/";
            string scope        = "http://localhost:31875/";

            // Register the app (this should be done elsewhere!)
            try
            {
                var x = new ApplicationRegistrationService();
                x.RegisterApplication(clientId, clientSecret, redirectUri, clientId);
            }
            catch
            {
            }

            var client = new SimpleOAuth2Client(
                new Uri(authorizeUri),
                new Uri("https://brewbuddy-prod.accesscontrol.windows.net/v2/OAuth2-13/"),
                clientId,
                clientSecret,
                scope,
                new Uri(redirectUri));

            if (string.IsNullOrWhiteSpace(code) && string.IsNullOrWhiteSpace(error))
            {
                return(Redirect(client.BuildAuthorizationUri().ToString()));
            }

            client.Authorize(code);

            HttpWebRequest webRequest = HttpWebRequest.Create(new Uri("http://localhost:31875/api/v1/Sample")) as HttpWebRequest;

            webRequest.Method        = WebRequestMethods.Http.Get;
            webRequest.ContentLength = 0;
            client.AppendAccessTokenTo(webRequest);

            var responseText = "";

            try
            {
                var response = webRequest.GetResponse();
                responseText = new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch (WebException wex)
            {
                responseText = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
            }

            return(Content(responseText));
        }
Esempio n. 5
0
        public void TestTheSetup()
        {
            ApplicationRegistrationService svc = GetTestService();
            string userName = 8.RandomLetters();

            UserAccounts.Data.User user = SetCurrentUser(userName, svc);
            Expect.AreEqual(userName, user.UserName);
            UserAccounts.Data.User sessionUser = Session.Get(svc.HttpContext).UserOfUserId;
            Expect.IsNotNull(sessionUser);
            Expect.AreEqual(userName, sessionUser.UserName, "UserName didn't match");
            Expect.AreEqual(sessionUser, svc.CurrentUser, "Users didn't match");
        }
Esempio n. 6
0
        public void CoreApplicationRegistryServiceMustBeLoggedInToRegister()
        {
            ApplicationRegistrationService svc = GetTestService();
            string              orgName        = 5.RandomLetters();
            string              appName        = 8.RandomLetters();
            ProcessDescriptor   descriptor     = ProcessDescriptor.ForApplicationRegistration(svc.ApplicationRegistrationRepository, "localhost", 8080, appName, orgName);
            CoreServiceResponse response       = svc.RegisterApplicationProcess(descriptor);

            Expect.IsFalse(response.Success);
            Expect.IsNotNull(response.Data);
            Expect.IsInstanceOfType <ApplicationRegistrationResult>(response.Data);
            Expect.AreEqual(ApplicationRegistrationStatus.Unauthorized, ((ApplicationRegistrationResult)response.Data).Status);
        }
        public ActionResult Index(string code, string error)
        {
            string authorizeUri = "http://localhost:31875/authorize";
            string clientId = "testclient3";
            string clientSecret = "testsecret";
            string redirectUri = "http://localhost:31875/";
            string scope = "http://localhost:31875/";

            // Register the app (this should be done elsewhere!)
            try
            {
                var x = new ApplicationRegistrationService();
                x.RegisterApplication(clientId, clientSecret, redirectUri, clientId);
            }
            catch
            {
            }

            var client = new SimpleOAuth2Client(
                new Uri(authorizeUri),
                new Uri("https://brewbuddy-prod.accesscontrol.windows.net/v2/OAuth2-13/"),
                clientId,
                clientSecret,
                scope,
                new Uri(redirectUri));

            if (string.IsNullOrWhiteSpace(code) && string.IsNullOrWhiteSpace(error))
            {
                return Redirect(client.BuildAuthorizationUri().ToString());
            }

            client.Authorize(code);

            HttpWebRequest webRequest = HttpWebRequest.Create(new Uri("http://localhost:31875/api/v1/Sample")) as HttpWebRequest;
            webRequest.Method = WebRequestMethods.Http.Get;
            webRequest.ContentLength = 0;
            client.AppendAccessTokenTo(webRequest);

            var responseText = "";
            try
            {
                var response = webRequest.GetResponse();
                responseText = new StreamReader(response.GetResponseStream()).ReadToEnd();
            }
            catch (WebException wex)
            {
                responseText = new StreamReader(wex.Response.GetResponseStream()).ReadToEnd();
            }

            return Content(responseText);
        }
Esempio n. 8
0
        public ActionResult Register()
        {
            var applicationRegistrationService = new ApplicationRegistrationService();

            try
            {
                //applicationRegistrationService.RemoveApplication("yourclientid");
                applicationRegistrationService.RegisterApplication("yourclientid", "yourclientsecret", "http://yourrealm/", "Just a description");
            }
            catch
            {
                // Pokemon handler: Gotta catch em all!
            }

            return(Content("All set!"));
        }
Esempio n. 9
0
        public void OrganizationGetsCreated()
        {
            Log.Default = new ConsoleLogger();
            Log.Default.StartLoggingThread();
            string userName = 4.RandomLetters();
            string orgName  = 5.RandomLetters();
            string appName  = 8.RandomLetters();
            ApplicationRegistrationService svc = GetTestServiceWithUser(userName);
            ProcessDescriptor   descriptor     = ProcessDescriptor.ForApplicationRegistration(svc.ApplicationRegistrationRepository, "localhost", 8080, appName, orgName);
            CoreServiceResponse response       = svc.RegisterApplicationProcess(descriptor);

            Expect.IsTrue(response.Success);
            var user = svc.ApplicationRegistrationRepository.OneUserWhere(c => c.UserName == userName);

            user = svc.ApplicationRegistrationRepository.Retrieve <ApplicationRegistration.Data.User>(user.Id);
            Expect.IsNotNull(user);
            Expect.AreEqual(1, user.Organizations.Count);
            Thread.Sleep(1000);
            Pass($"{nameof(OrganizationGetsCreated)} Test Passed");
        }
Esempio n. 10
0
        private static UserAccounts.Data.User SetCurrentUser(string userName, ApplicationRegistrationService svc)
        {
            IHttpContext ctx = Substitute.For <IHttpContext>();

            ctx.Request = Substitute.For <IRequest>();
            ctx.Request.Url.Returns(new Uri("http://test.cxm"));
            NameValueCollection headers = new NameValueCollection();

            headers["REMOTE_ADDR"] = "127.0.0.1";
            ctx.Request.Headers.Returns(headers);
            ctx.Response = Substitute.For <IResponse>();
            CookieCollection Cookies       = new CookieCollection();
            Cookie           sessionCookie = new Cookie(Session.CookieName, "0368c7fde0a40272d42e14e224d37761dbccef665116ccb063ae31aaa7708d72");

            Cookies.Add(sessionCookie);
            ctx.Request.Cookies.Returns(Cookies);
            ctx.Response.Cookies.Returns(Cookies);
            svc.HttpContext = ctx;
            SessionCollection sessions = Session.LoadAll();

            sessions.Delete();
            UserCollection users = UserAccounts.Data.User.LoadAll();

            users.Delete();
            UserAccounts.Data.User result = UserAccounts.Data.User.Create(userName);
            Session session = Session.Get(ctx);

            session.UserId = result.Id;
            session.Save();
            IEnumerable <Organization> organizations = svc.ApplicationRegistrationRepository.RetrieveAll <Organization>();

            organizations.Each(o => svc.ApplicationRegistrationRepository.Delete(o));
            Expect.AreEqual(0, svc.ApplicationRegistrationRepository.RetrieveAll <Organization>().Count());
            IEnumerable <ApplicationRegistration.Data.Application> apps = svc.ApplicationRegistrationRepository.RetrieveAll <ApplicationRegistration.Data.Application>();

            apps.Each(a => svc.ApplicationRegistrationRepository.Delete(a));
            Expect.AreEqual(0, svc.ApplicationRegistrationRepository.RetrieveAll <ApplicationRegistration.Data.Application>().Count());
            svc.ApplicationRegistrationRepository.RetrieveAll <ApplicationRegistration.Data.Machine>().Each(h => svc.ApplicationRegistrationRepository.Delete(h));
            return(result);
        }
Esempio n. 11
0
        public void CoreApplicationRegistryServiceNotLoggedInIsAnonymous()
        {
            ApplicationRegistrationService svc = GetTestService();

            Expect.AreSame(UserAccounts.Data.User.Anonymous, svc.CurrentUser);
        }