Beispiel #1
0
        // GET: Calendar
        public async Task <ActionResult> Index()
        {
            // Make sure the user is signed in
            if (!Request.IsAuthenticated)
            {
                return(new RedirectResult("/Account/Index"));
            }

            string tenantId = ClaimsPrincipal.Current.FindFirst(tenantIdClaimType).Value;

            try
            {
                // Try to get a token for the tenant
                ConfidentialClientApplication daemonClient = new ConfidentialClientApplication(String.Format(authorityFormat, tenantId), Startup.clientId, Startup.redirectUri, new ClientCredential(Startup.clientSecret), null);
                AuthenticationResult          authResult   = await daemonClient.AcquireTokenForClient(new string[] { msGraphScope }, null);

                // Query for list of users in the tenant, to ensure we have been granted the necessary permissions
                HttpClient         client  = new HttpClient();
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, msGraphQuery);
                request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", authResult.Token);
                HttpResponseMessage response = await client.SendAsync(request);

                // If we get back a 403, we need to ask the admin for permissions
                if (response.StatusCode == System.Net.HttpStatusCode.Forbidden)
                {
                    daemonClient.AppTokenCache.Clear(Startup.clientId);
                    return(new RedirectResult("/Account/GrantPermissions"));
                }
                else if (!response.IsSuccessStatusCode)
                {
                    throw new HttpResponseException(response.StatusCode);
                }
            }
            catch (MsalException ex)
            {
                // If we can't get a token, we need to ask the admin for permissions as well
                if (ex.ErrorCode == "failed_to_acquire_token_silently")
                {
                    return(new RedirectResult("/Account/GrantPermissions"));
                }

                return(View("Error"));
            }
            catch (Exception ex)
            {
                return(View("Error"));
            }

            // If we can get a token & make the query, permissions have been granted and we can proceed to showing the list of users
            ViewBag.TenantId = tenantId;
            ViewBag.Users    = SyncController.GetUsersForTenant(tenantId);

            return(View());
        }
        // GET: Calendar
        public async Task <ActionResult> Index()
        {
            // Make sure the user is signed in
            //if (!Request.IsAuthenticated)
            //{
            //    return new RedirectResult("/Account/Index");
            //}

            //// Show the list of users that have been sync'd to the database
            //string tenantId = ClaimsPrincipal.Current.FindFirst(tenantIdClaimType).Value;
            ViewBag.TenantId = "0e414957-46cc-4c67-98dc-de08f56bcad6";
            ViewBag.Users    = await SyncController.GetUsersForTenant(ViewBag.TenantId);

            return(View());
        }
Beispiel #3
0
        // GET: Calendar
        public ActionResult Index()
        {
            // Make sure the user is signed in
            if (!this.Request.IsAuthenticated)
            {
                return(new RedirectResult("/Account/Index"));
            }

            // Show the list of users that have been sync'd to the database
            string tenantId = ClaimsPrincipal.Current.FindFirst(TenantIdClaimType).Value;

            this.ViewBag.TenantId = tenantId;
            this.ViewBag.Users    = SyncController.GetUsersForTenant(tenantId);

            return(this.View());
        }
        // GET: Calendar
        public ActionResult Index()
        {
            // Make sure the user is signed in
            //if (!Request.IsAuthenticated)
            //{
            //    return new RedirectResult("/Account/Index");
            //}

            // Show the list of users that have been sync'd to the database
            string tenantId = "adcb46ee-de3a-485e-b3c9-7c83a2d4cbcf";

            ViewBag.TenantId = tenantId;
            ViewBag.Users    = SyncController.GetUsersForTenant(tenantId);

            string userId = "*****@*****.**";

            ViewBag.UserId = userId;
            ViewBag.Drive  = OneDriveController.GetDriveForUser(userId);

            return(View());
        }