Exemple #1
0
        public async Task<ClientContext> GetClientContext(string url)
        {
            AuthenticationHelper authHelper = new AuthenticationHelper();

            ClientContext clientContext = TokenHelper.GetClientContextWithAccessToken(url, (await authHelper.GetToken(SettingsHelper.SharePointResource)).AccessToken);

            return clientContext;
        }
Exemple #2
0
        public void ConfigureAuth(IAppBuilder app)
        {
            ApplicationDbContext db = new ApplicationDbContext();

            app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);

            app.UseCookieAuthentication(new CookieAuthenticationOptions());

            OpenIdConnectAuthenticationOptions options = new OpenIdConnectAuthenticationOptions();
            options.ClientId = SettingsHelper.ClientId;
            options.Authority = SettingsHelper.AzureADAuthority;
            options.PostLogoutRedirectUri = SettingsHelper.LogoutAuthority;

            OpenIdConnectAuthenticationNotifications notifications = new OpenIdConnectAuthenticationNotifications();
            notifications.AuthorizationCodeReceived = (context) =>
            {
                string code = context.Code;

                AuthenticationHelper authHelper = new AuthenticationHelper();
                
                String signInUserId = context.AuthenticationTicket.Identity.FindFirst(ClaimTypes.NameIdentifier).Value;

                AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.AzureADAuthAuthority);
                AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), authHelper.GetClientAssertionCertificate(), null);

                return Task.FromResult(0);
            };

            notifications.RedirectToIdentityProvider = (context) =>
            {
                string appBaseUrl = context.Request.Scheme + "://" + context.Request.Host + context.Request.PathBase;
                context.ProtocolMessage.RedirectUri = appBaseUrl + "/";
                context.ProtocolMessage.PostLogoutRedirectUri = appBaseUrl;

                return Task.FromResult(0);
            };

            notifications.AuthenticationFailed = (context) =>
            {
                context.HandleResponse();
                return Task.FromResult(0);
            };

            options.Notifications = notifications;

            app.UseOpenIdConnectAuthentication(options);
        }
Exemple #3
0
 private async Task SetAccessToken()
 {
     AuthenticationHelper authHelper = new AuthenticationHelper();
     _token = await authHelper.GetToken(SettingsHelper.GraphResource);
 }
Exemple #4
0
        private async Task SetAccessToken()
        {
            AuthenticationHelper authHelper = new AuthenticationHelper();

            _token = await authHelper.GetToken(SettingsHelper.GraphResource);
        }