/// <summary> /// Instantiates an Authenticator that reflects the properties contains in the specified Map. /// </summary> /// <param name="props">A Map containing configuration properties</param> /// <returns>An Authenticator instance</returns> private static Authenticator CreateAuthenticator(Dictionary <string, string> props) { Authenticator authenticator = null; // If auth type was not specified, we'll use "iam" as the default. props.TryGetValue(Authenticator.PropNameAuthType, out string authType); if (string.IsNullOrEmpty(authType)) { authType = Authenticator.AuthTypeIam; } if (authType.Equals(Authenticator.AuthTypeNoAuth, StringComparison.InvariantCultureIgnoreCase)) { authenticator = new NoAuthAuthenticator(props); } else if (authType.Equals(Authenticator.AuthTypeBasic, StringComparison.InvariantCultureIgnoreCase)) { authenticator = new BasicAuthenticator(props); } else if (authType.Equals(Authenticator.AuthTypeIam, StringComparison.InvariantCultureIgnoreCase)) { authenticator = new IamAuthenticator(props); } else if (authType.Equals(Authenticator.AuthTypeCp4d, StringComparison.InvariantCultureIgnoreCase)) { authenticator = new CloudPakForDataAuthenticator(props); } else if (authType.Equals(Authenticator.AuthTypeBearer, StringComparison.InvariantCultureIgnoreCase)) { authenticator = new BearerTokenAuthenticator(props); } return(authenticator); }
// Update is called once per frame public IEnumerator CreateService() { if (string.IsNullOrEmpty(bearerToken)) { throw new IBMException("Plesae provide Bearer Token for the service."); } // Option 1 // Create credential and instantiate service using bearer token BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken: bearerToken); // Option 2 // Create credential and instantiate service using username/password // var authenticator = new CloudPakForDataAuthenticator( // url: "https://{cpd_cluster_host}{:port}", // username: "******", // password: "******" // ); // Wait for tokendata while (!authenticator.CanAuthenticate()) { yield return(null); } service = new DiscoveryService(versionDate, authenticator); service.SetServiceUrl("service_url"); if (!string.IsNullOrEmpty(serviceUrl)) { service.SetServiceUrl(serviceUrl); } Runnable.Run(ExampleListCollections()); }
public void Setup() { Authenticator discoveryAuthenticator = new BearerTokenAuthenticator(bearerToken: bearerToken); service = new DiscoveryService(versionDate: versionDate, authenticator: discoveryAuthenticator); service.SetServiceUrl(serviceUrl: serviceUrl); service.DisableSslVerification(true); }
public void TestConstructionBearerToken() { var bearerToken = "bearerToken"; BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken); Assert.IsNotNull(authenticator); Assert.IsTrue(authenticator.AuthenticationType == Authenticator.AuthTypeBearer); Assert.IsTrue(authenticator.BearerToken == bearerToken); }
public void TestUpdateTokenToken() { var bearerToken0 = "bearerToken0"; var bearerToken1 = "bearerToken1"; BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken0); authenticator.BearerToken = bearerToken1; Assert.IsNotNull(authenticator); Assert.IsTrue(authenticator.AuthenticationType == Authenticator.AuthTypeBearer); Assert.IsTrue(authenticator.BearerToken == bearerToken1); }
public void TestAuthenticate() { var bearerToken = "bearerToken"; BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken); IClient client = new IBMHttpClient(); authenticator.Authenticate(client); Assert.IsNotNull(client); Assert.IsNotNull(client.BaseClient); Assert.IsNotNull(client.BaseClient.DefaultRequestHeaders.Authorization); Assert.IsTrue(client.BaseClient.DefaultRequestHeaders.Authorization.ToString() == "Bearer " + bearerToken); }
public void TestConstructionDictionary() { var bearerToken = "bearerToken"; Dictionary <string, string> config = new Dictionary <string, string>(); config.Add(Authenticator.PropNameBearerToken, bearerToken); BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(config); Assert.IsNotNull(authenticator); Assert.IsTrue(authenticator.AuthenticationType == Authenticator.AuthTypeBearer); Assert.IsTrue(authenticator.BearerToken == bearerToken); }
public void Setup() { Authenticator discoveryAuthenticator = new BearerTokenAuthenticator(bearerToken: bearerToken); service = new DiscoveryService(version: versionDate, authenticator: discoveryAuthenticator); service.SetServiceUrl(serviceUrl: serviceUrl); service.DisableSslVerification(true); //service = new DiscoveryService(versionDate); //service.SetServiceUrl(serviceUrl); var creds = CredentialUtils.GetServiceProperties("discovery"); creds.TryGetValue("PROJECT_ID", out projectId); creds.TryGetValue("COLLECTION_ID", out collectionId); }
public IEnumerator UnityTestSetup() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken: "{bearer_token}"); if (service == null) { service = new DiscoveryService(versionDate, authenticator); } service.SetServiceUrl("service_url"); service.DisableSslVerification = true; while (!service.Authenticator.CanAuthenticate()) { yield return(null); } }
public void Setup() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator( bearerToken: bearerToken ); service = new DiscoveryService("2019-10-03", authenticator); service.SetServiceUrl(serviceUrl); service.DisableSslVerification(true); var listEnvironmentsResult = service.ListEnvironments(); environmentId = listEnvironmentsResult.Result.Environments[0].EnvironmentId; var listCollectionsResult = service.ListCollections(environmentId: environmentId); collectionId = listCollectionsResult.Result.Collections[0].CollectionId; }
//[UnityTest, Order(20)] public IEnumerator TestAnalyzeDocument() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator( bearerToken: "{BEARER_TOKEN}" ); DiscoveryService cpdService = new DiscoveryService(versionDate, authenticator); cpdService.SetServiceUrl("{SERVICE_URL}"); cpdService.WithHeader("X-Watson-Test", "1"); Log.Debug("DiscoveryServiceV2IntegrationTests", "Attempting to AnalyzeDocument..."); AnalyzedDocument analyzeDocumentResponse = null; using (FileStream fs = File.OpenRead(analyzeDocumentFile)) { using (MemoryStream ms = new MemoryStream()) { fs.CopyTo(ms); cpdService.AnalyzeDocument( callback: (DetailedResponse <AnalyzedDocument> response, IBMError error) => { Log.Debug("DiscoveryServiceV2IntegrationTests", "AnalyzeDocument result: {0}", response.Response); analyzeDocumentResponse = response.Result; Assert.IsNull(error); Assert.IsNotNull(analyzeDocumentResponse); }, projectId: "{projectId}", collectionId: "{collectionId}", file: ms, filename: "exampleConfigurationData.json", fileContentType: "application/json" ); } } while (analyzeDocumentResponse == null) { yield return(null); } }
public void TestBadBearerTokenBracketEnd() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator("username}"); }
public void TestBadBearerTokenBracketBeginning() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator("{username"); }
public void TestNullBearerToken() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator(bearerToken: null); }
public void TestBadBearerTokenBeginningQuoteEnd() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator("\"username\""); }
public void TestBadBearerTokenQuoteBeginning() { BearerTokenAuthenticator authenticator = new BearerTokenAuthenticator("\"username"); }