Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                string sharePointUrl  = args[0];
                string username       = args[1];
                string password       = args[2];
                bool   integratedAuth = bool.Parse(args[3]);

                //
                var spa = new SharePointAuth(new Uri(sharePointUrl),
                                             username,
                                             password,
                                             integratedAuth);

                // Attempt to sign the user into SharePoint Online using Integrated Windows Auth or username + password
                cc = spa.Authenticate();

                using (ClientContext ctx = new ClientContext(sharePointUrl))
                {
                    ctx.ExecutingWebRequest += new EventHandler <WebRequestEventArgs>(ctx_ExecutingWebRequest);

                    if (ctx != null)
                    {
                        ctx.Load(ctx.Web);  // Query for Web
                        ctx.ExecuteQuery(); // Execute
                        System.Console.WriteLine(ctx.Web.Title);
                        System.Console.ReadKey();
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                //Get SharePoint Access Token
                string token = SharePointAuth.GetSessionToken();

                if (!String.IsNullOrEmpty(token))
                {
                    Debug.WriteLine("Bearer token found: " + token);
                    HttpWebRequest request = CreateRequest(context, token);
                    CreateResponse(context, request);
                }
                else
                {
                    Debug.WriteLine("No bearer token found in WebProxy.ashx.cs");
                    context.Response.StatusCode = (int)HttpStatusCode.Redirect;
                    context.Response.End();
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine(exp.Message);
            }
        }
        public async Task <ActionResult> RefreshToken(string returnUrl)
        {
            await SharePointAuth.EnsureClientCreated();

            Response.Redirect(Server.UrlDecode(returnUrl));
            return(View());
        }
Ejemplo n.º 4
0
        public override async Task ProcessRequestAsync(HttpContext context)
        {
            try
            {
                //Get SharePoint Access Token
                var token = await SharePointAuth.GetAccessToken(SettingsHelper.SharePointDomainUri);

                if (!String.IsNullOrEmpty(token))
                {
                    Debug.WriteLine("Bearer token found: " + token);
                    HttpWebRequest request = CreateRequest(context, token);
                    CreateResponse(context, request);
                }
                else
                {
                    Debug.WriteLine("No bearer token found in WebProxy.ashx.cs");
                    //context.Response.StatusCode = (int)HttpStatusCode.Redirect;
                    context.Response.End();
                }
            }
            catch (Exception exp)
            {
                Debug.WriteLine("Error in WebProxy ProcessRequest: " + exp.Message);
            }
        }
Ejemplo n.º 5
0
        //Quick and dirty way to test that auth is working properly to AD and SharePoint
        public async Task <ActionResult> Title()
        {
            var token = await SharePointAuth.GetAccessToken(SettingsHelper.SharePointDomainUri);

            WebClient wc = new WebClient();

            wc.Headers.Add("Method", "GET");
            wc.Headers.Add("Accept", "application/json;odata=verbose");
            wc.Headers.Add("Authorization", "Bearer " + token);
            var title = await wc.DownloadStringTaskAsync(SettingsHelper.SharePointApiServiceUri + "web/title");

            ViewBag.Title = title;
            return(View());
        }
        public async Task <ActionResult> Login()
        {
            try
            {
                var client = await SharePointAuth.EnsureClientCreated();

                Response.Redirect("/index.html");
                return(View());
            }
            catch (RedirectRequiredException ex)
            {
                return(Redirect(ex.RedirectUri.ToString()));
            }
        }
Ejemplo n.º 7
0
 public ActionResult RefreshToken(string returnUrl)
 {
     SharePointAuth.RefreshSession();
     return(new RedirectResult(Server.UrlDecode(returnUrl)));
 }
        public async Task <ActionResult> Title()
        {
            ViewBag.Title = await SharePointAuth.GetSiteTitle();

            return(View());
        }