예제 #1
0
        public void Login_context_test()
        {
            if (TestUtil.IgnoreCertificate)
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            }
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;

            var client = TestUtil.GetClient();
            var authEndpoint = client.Info.GetInfo().Result.AuthorizationEndpoint;
            var authUri = new Uri(authEndpoint.TrimEnd('/') + "/oauth/token");


            UAAClient uaaClient = new UAAClient(authUri);

            var context = uaaClient.Login(credentials).Result;

            Assert.IsTrue(context.IsLoggedIn);
            Assert.AreEqual(context.Uri, authUri);
            Assert.IsNotNull(context.Token.AccessToken);
            Assert.IsNotNull(context.Token.RefreshToken);
            Assert.AreEqual(TestUtil.User, context.Token.UserName);
            Assert.IsNotNull(context.Token.UserGuid);
            Assert.IsFalse(context.Token.IsExpired);
            Assert.IsTrue(context.Token.Expires > DateTime.Now);

        }
예제 #2
0
        public void TestUAAClientNotLoggedIn()
        {
            UAAClient uaaClient = new UAAClient(new Uri("http://uaa.foo.bar"));

            Assert.IsFalse(uaaClient.Context.IsLoggedIn);

        }
예제 #3
0
 public static UAAClient GetUAAClient(Token authenticationToken)
 {
     UAAClient uaaClient = new UAAClient(new Uri("http://uaa.foo.bar"));
     TestAuthentication authentication = new TestAuthentication();
     authentication.TestToken = authenticationToken;
     uaaClient.Authentication = authentication;
     return uaaClient;
 }
예제 #4
0
        public void Login_refresh_token_test()
        {
            if (TestUtil.IgnoreCertificate)
            {
                System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);
            }
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;

            var client = TestUtil.GetClient();
            var authEndpoint = client.Info.GetInfo().Result.AuthorizationEndpoint;
            var authUri = new Uri(authEndpoint.TrimEnd('/') + "/oauth/token");


            UAAClient uaaClient = new UAAClient(authUri);

            var context = uaaClient.Login(credentials).Result;

            client.Login(context.Token.RefreshToken).Wait();

            client.Buildpacks.ListAllBuildpacks().Wait();
        }
예제 #5
0
        public void TestUAAClientExceptionGenerateContextNotLogedIn()
        {
            UAAClient uaaClient = new UAAClient(new Uri("http://uaa.foo.bar"));
            AuthenticationContext context = null;

            try
            {
                context = uaaClient.GenerateContext().Result;
                Assert.Fail("No exception was thrown when generating context for an unauthorized client");
            }
            catch (AggregateException ae)
            {
                foreach (var ex in ae.Flatten().InnerExceptions)
                {
                    if (ex.GetType() != typeof(AuthenticationException))
                    {
                        Assert.Fail(string.Format(CultureInfo.InvariantCulture, "Expected type of AuthenticationException but got {0}", ex.ToString()));
                    }
                }
            }


        }
        public async Task<AuthenticationContext> Login(string refreshToken)
        {
            var info = await this.Info.GetInfo();

            var authUrl = string.Format(CultureInfo.InvariantCulture, "{0}{1}", info.AuthorizationEndpoint.TrimEnd('/'), "/oauth/token");
            this.UAAClient = new UAAClient(new Uri(authUrl), this.HttpProxy, this.SkipCertificateValidation);

            var context = await this.UAAClient.Login(refreshToken);

            if (context.IsLoggedIn)
            {
                //// Workaround for HCF. Some CC requests (e.g. dev role + bind route, update app, etc..) will fail the first time after login with 401.
                //// Calling the CC's /v2/info endpoint will prevent this misbehavior.
                await this.Info.GetInfo();
            }

            return context;
        }