예제 #1
0
        public async Task <ActionResult> Index(string authType)
        {
            string redirectUri      = this.Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/Home/App";
            string authorizationUrl = OAuthController.GetAuthorizationUrl(ServiceResourceId, new Uri(redirectUri));

            return(new RedirectResult(authorizationUrl));
        }
예제 #2
0
        public async Task <ActionResult> Index(string authType)
        {
            if (authType == "O365")
            {
                try
                {
                    if (_discoveryContext == null)
                    {
                        _discoveryContext = await DiscoveryContext.CreateAsync();
                    }
                    var dcr = await _discoveryContext.DiscoverResourceAsync(ServiceResourceId);

                    _lastLoggedInUser = dcr.UserId;
                    string accessToken = (await _discoveryContext.AuthenticationContext.AcquireTokenByRefreshTokenAsync(new SessionCache().Read("RefreshToken"), new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(_discoveryContext.AppIdentity.ClientId, _discoveryContext.AppIdentity.ClientSecret), ServiceResourceId)).AccessToken;

                    OAuthController.SaveAccessTokenInCache(ServiceResourceId, accessToken, DateTime.Now.AddMinutes(10).ToString());
                    return(new RedirectResult("/Home/App"));
                }
                catch (RedirectRequiredException ex)
                {
                    return(Redirect(ex.RedirectUri.ToString()));
                }
            }
            else
            {
                string redirectUri      = this.Request.Url.GetLeftPart(UriPartial.Authority).ToString() + "/Home/App";
                string authorizationUrl = OAuthController.GetAuthorizationUrl(ServiceResourceId, new Uri(redirectUri));
                return(new RedirectResult(authorizationUrl));
            }
        }
예제 #3
0
        public async Task <ActionResult> O365API()
        {
            if (_discoveryContext == null)
            {
                _discoveryContext = await DiscoveryContext.CreateAsync();
            }
            var dcr = await _discoveryContext.DiscoverResourceAsync(ServiceResourceId);

            _lastLoggedInUser = dcr.UserId;
            string accessToken = (await _discoveryContext.AuthenticationContext.AcquireTokenByRefreshTokenAsync(new SessionCache().Read("RefreshToken"), new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(_discoveryContext.AppIdentity.ClientId, _discoveryContext.AppIdentity.ClientSecret), ServiceResourceId)).AccessToken;

            OAuthController.SaveAccessTokenInCache(ServiceResourceId, accessToken, DateTime.Now.AddMinutes(10).ToString());
            return(new RedirectResult("/Home/App"));
        }