/// <summary>
        /// Adds the Bearer authorisation token from Active Directory for the specified credentials.
        /// </summary>
        /// <param name="client">The client to add the authorisation token to.</param>
        /// <param name="uri">The location of the Active Directory Tenant.</param>
        /// <param name="clientid">The client id for the application to be authenticated against.</param>
        /// <param name="clientSecret">The client id for the application to be authenticated against.</param>
        /// <param name="applicationId">The application id of the calling application.</param>
        /// <returns>The client instance.</returns>
        public static HttpClient AuthenticateAgainstActiveDirectory(this HttpClient client, string uri, string clientid, string clientSecret, string applicationId)
        {
            var result = ActiveDirectoryAuthenticator.GetAuthenticationResult(uri, clientid, clientSecret, applicationId);

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);

            return(client);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var auth = new ActiveDirectoryAuthenticator(new InMemoryStore());

            Guid?token;
            User user;

            auth.Credentials("dan.hintea", "Lpl4User2012", out token);
            auth.Authenticate(token.Value, out user);

            Console.WriteLine("Done @ {0}", DateTime.Now);
            Console.ReadKey();
        }
Beispiel #3
0
        public void AuthenticateTest(ActiveDirectoryAuthenticatorTestArgs args)
        {
            XElement x = new XElement("Authentication");

            x.Add(new XAttribute("AuthID", "testid"));
            x.Add(new XAttribute("Domain", args.Domain));
            ActiveDirectoryAuthenticator           adauth = new ActiveDirectoryAuthenticator(x);
            ActiveDirectoryAuthenticatorTestSource source = new ActiveDirectoryAuthenticatorTestSource();

            adauth.PasswordSource = source;
            adauth.UsernameSource = source;
            source.Username       = args.AuthUser;
            source.SecurePassword = GetSecureStringFromString(args.AuthPassword);
            adauth.RequiredGroups = args.Groups;
            AuthState state = adauth.Authenticate();

            NUnit.Framework.Assert.AreEqual(args.ExpectedResult, state);
        }
        public void IsMemberOfGroupsTest(ActiveDirectoryMethodsTestArgs args)
        {
            ActiveDirectoryAuthenticatorTestArgs authargs = args.AuthArgs;
            XElement x = new XElement("Authentication");

            x.Add(new XAttribute("AuthID", "testid"));
            x.Add(new XAttribute("Domain", authargs.Domain));
            ActiveDirectoryAuthenticator           adauth = new ActiveDirectoryAuthenticator(x);
            ActiveDirectoryAuthenticatorTestSource source = new ActiveDirectoryAuthenticatorTestSource();

            adauth.PasswordSource = source;
            adauth.UsernameSource = source;
            source.Username       = authargs.AuthUser;
            source.SecurePassword = GetSecureStringFromString(authargs.AuthPassword);
            adauth.RequiredGroups = args.AuthArgs.Groups;
            adauth.Authenticate();
            bool result = ActiveDirectoryMethods.IsUserMemberOfGroups(adauth.Context, args.UserName, args.Groups);

            Assert.AreEqual(args.ExpectedResult, result);
        }