@@ -89,6 +89,13 @@ If you have more than one plan, you can use `CredentialUtils` to get the service
89
89
90
90
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
91
91
92
+ As of ` v9.2.1 ` , the preferred approach of initializing an authenticator is the builder pattern. This pattern supports
93
+ constructing the authenticator with only the properties that you need. Also, if you're authenticating to a Watson service
94
+ on Cloud Pak for Data that supports IAM, you must use the builder pattern.
95
+
96
+ - You can initialize the authenticator with either of the following approaches:
97
+ - In the builder of the authenticator (builder pattern).
98
+ - In the constructor of the authenticator (deprecated, but still available).
92
99
- With some service instances, you authenticate to the API by using ** [ IAM] ( #iam ) ** .
93
100
- In other instances, you authenticate by providing the ** [ username and password] ( #username-and-password ) ** for the service instance.
94
101
- If you're using a Watson service on Cloud Pak for Data, you'll need to authenticate in a [ specific way] ( #cloud-pak-for-data ) .
@@ -152,6 +159,18 @@ You supply either an IAM service **API key** or an **access token**:
152
159
153
160
Supplying the IAM API key:
154
161
162
+ Builder pattern approach:
163
+
164
+ ``` java
165
+ // letting the SDK manage the IAM token
166
+ Authenticator authenticator = new IamAuthenticator .Builder ()
167
+ .apikey(" <iam_api_key>" )
168
+ .build();
169
+ Discovery service = new Discovery (" 2019-04-30" , authenticator);
170
+ ```
171
+
172
+ Deprecated constructor approach:
173
+
155
174
``` java
156
175
// letting the SDK manage the IAM token
157
176
Authenticator authenticator = new IamAuthenticator (" <iam_api_key>" );
@@ -168,6 +187,18 @@ Discovery service = new Discovery("2019-04-30", authenticator);
168
187
169
188
#### Username and password
170
189
190
+ Builder pattern approach:
191
+
192
+ ``` java
193
+ Authenticator authenticator = new BasicAuthenticator .Builder ()
194
+ .username(" <username>" )
195
+ .password(" <password>" )
196
+ .build();
197
+ Discovery service = new Discovery (" 2019-04-30" , authenticator);
198
+ ```
199
+
200
+ Deprecated constructor approach:
201
+
171
202
``` java
172
203
Authenticator authenticator = new BasicAuthenticator (" <username>" , " <password>" );
173
204
Discovery service = new Discovery (" 2019-04-30" , authenticator);
@@ -190,6 +221,23 @@ service.configureClient(options);
190
221
#### Cloud Pak for Data
191
222
Like IAM, you can pass in credentials to let the SDK manage an access token for you or directly supply an access token to do it yourself.
192
223
224
+ Builder pattern approach:
225
+
226
+ ``` java
227
+ // letting the SDK manage the token
228
+ Authenticator authenticator = new CloudPakForDataAuthenticator .Builder ()
229
+ .url(" <CP4D token exchange base URL>" )
230
+ .username(" <username>" )
231
+ .password(" <password>" )
232
+ .disableSSLVerification(true )
233
+ .headers(null )
234
+ .build();
235
+ Discovery service = new Discovery (" 2019-04-30" , authenticator);
236
+ service. setServiceUrl(" <service CP4D URL>" );
237
+ ```
238
+
239
+ Deprecated constructor approach:
240
+
193
241
``` java
194
242
// letting the SDK manage the token
195
243
Authenticator authenticator = new CloudPakForDataAuthenticator (
0 commit comments