示例#1
0
        public async Task <ActionResult> Index(string code)
        {
            if (string.IsNullOrEmpty(code))
            {
                var GraphResourceId = "https://graph.microsoft.com";

                string authorizationRequest = String.Format(
                    "{0}/oauth2/authorize?response_type=code&client_id={1}&resource={2}&redirect_uri={3}&state={4}",
                    SettingsHelper.Authority,
                    Uri.EscapeDataString(SettingsHelper.ClientID),
                    Uri.EscapeDataString(GraphResourceId),
                    Uri.EscapeDataString(string.Format("{0}/", Request.Url.GetLeftPart(UriPartial.Authority))),
                    Uri.EscapeDataString(Guid.NewGuid().ToString())
                    );

                return(new RedirectResult(authorizationRequest));
            }
            else
            {
                IOrderedEnumerable <Event> events = await CalendarAPISample.GetCalendarEvents(code);

                ViewBag.Events = events;
            }
            return(View());
        }
        public async Task <ActionResult> Index(string code)
        {
            var webUrl = string.Format("{0}/", Request.Url.GetLeftPart(UriPartial.Authority));

            if (string.IsNullOrEmpty(code))
            {
                var adAuthority = "https://login.microsoftonline.com";
                var scope       = "Calendars.Read openid email profile offline_access";

                string authorizationRequest = String.Format(
                    "{0}/common/oauth2/v2.0/authorize?response_type=code&client_id={1}&redirect_uri={2}&scope={3}&state={4}",
                    adAuthority,
                    Uri.EscapeDataString(SettingsHelper.AppId),
                    Uri.EscapeDataString(webUrl),
                    scope,
                    Uri.EscapeDataString(Guid.NewGuid().ToString())
                    );

                return(new RedirectResult(authorizationRequest));
            }
            else
            {
                IOrderedEnumerable <Event> events = await CalendarAPISample.GetCalendarEvents(code, webUrl);

                ViewBag.Events = events;
            }
            return(View());
        }
        public async Task <ActionResult> Index()
        {
            IOrderedEnumerable <IEvent> events = await CalendarAPISample.GetCalendarEvents();

            ViewBag.Events = events;
            return(View());
        }
        public async Task <ActionResult> Index()
        {
            try
            {
                IOrderedEnumerable <IEvent> events = await CalendarAPISample.GetCalendarEvents();

                ViewBag.Events = events;
            }
            catch (RedirectRequiredException x)
            {
                return(Redirect(x.RedirectUri.ToString()));
            }
            return(View());
        }