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.IsFalse(context.Token.IsExpired); Assert.IsTrue(context.Token.Expires > DateTime.Now); }
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); }
internal static UAAClient GetUAAClient() { var cfclient = GetClient(); var serverInfo = cfclient.Info.GetInfo().Result; var authEndpoint = serverInfo.AuthorizationEndpoint; var authUri = new Uri(authEndpoint.TrimEnd('/') + "/oauth/token"); UAAClient uaaClient = new UAAClient(authUri); return(uaaClient); }
public async Task <AuthenticationContext> Login(string refreshToken) { var info = await this.Info.GetInfo(); var authUrl = 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); }
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(CloudCredentials credentials) { if (this.AuthorizationEndpoint == null) { var info = await this.Info.GetInfo(); this.AuthorizationEndpoint = new Uri(string.Format(CultureInfo.InvariantCulture, "{0}{1}", info.AuthorizationEndpoint.TrimEnd('/'), "/oauth/token")); } this.UAAClient = new UAAClient(this.AuthorizationEndpoint, this.HttpProxy, this.SkipCertificateValidation); var context = await this.UAAClient.Login(credentials); 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); }
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(); }
public void TestUAAClientNotLoggedIn() { UAAClient uaaClient = new UAAClient(new Uri("http://uaa.foo.bar")); Assert.IsFalse(uaaClient.Context.IsLoggedIn); }