示例#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."));
        }
        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));
        }
        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);
        }
示例#4
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!"));
        }
 private void _RegisterIfMissing()
 {
     try
     {
         if (!mRegistrationService.IsApplicationRegistered(mInfo))
         {
             this.Log().Information("Registering application");
             mRegistrationService.RegisterApplication(mInfo);
         }
         else
         {
             this.Log().Information("Application already registered");
         }
     }
     catch (Exception ex)
     {
         this.Log().Error(ex, "Failed to register application");
     }
 }