@@ -25,6 +25,7 @@ public abstract class WatsonService : IWatsonService
2525 {
2626 const string PATH_AUTHORIZATION_V1_TOKEN = "/authorization/api/v1/token" ;
2727 const string ICP_PREFIX = "icp-" ;
28+ const string APIKEY_AS_USERNAME = "apikey" ;
2829 public IClient Client { get ; set ; }
2930
3031 public string ServiceName { get ; set ; }
@@ -89,7 +90,7 @@ protected WatsonService(string serviceName, string url, IClient httpClient)
8990 /// <param name="password">The password</param>
9091 public void SetCredential ( string userName , string password )
9192 {
92- if ( userName == "apikey" && ! password . StartsWith ( ICP_PREFIX ) )
93+ if ( userName == APIKEY_AS_USERNAME && ! password . StartsWith ( ICP_PREFIX ) )
9394 {
9495 TokenOptions tokenOptions = new TokenOptions ( )
9596 {
@@ -112,19 +113,26 @@ public void SetCredential(string userName, string password)
112113 /// <param name="options"></param>
113114 public void SetCredential ( TokenOptions options )
114115 {
115- if ( ! string . IsNullOrEmpty ( options . ServiceUrl ) )
116- {
117- if ( ! _userSetEndpoint )
118- {
119- this . Endpoint = options . ServiceUrl ;
120- }
116+ if ( options . IamApiKey . StartsWith ( ICP_PREFIX ) )
117+ {
118+ SetCredential ( APIKEY_AS_USERNAME , options . IamApiKey ) ;
121119 }
122120 else
123- {
124- options . ServiceUrl = this . Endpoint ;
125- }
126-
127- _tokenManager = new TokenManager ( options ) ;
121+ {
122+ if ( ! string . IsNullOrEmpty ( options . ServiceUrl ) )
123+ {
124+ if ( ! _userSetEndpoint )
125+ {
126+ this . Endpoint = options . ServiceUrl ;
127+ }
128+ }
129+ else
130+ {
131+ options . ServiceUrl = this . Endpoint ;
132+ }
133+
134+ _tokenManager = new TokenManager ( options ) ;
135+ }
128136 }
129137
130138 public void SetEndpoint ( string url )
0 commit comments