Skip to content

Commit 59ee618

Browse files
authored
Merge pull request #1194 from watson-developer-cloud/update-readme
docs(readme): update readme to reflect new builder pattern for the authenticators
2 parents 978e04a + 7a110f8 commit 59ee618

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ If you have more than one plan, you can use `CredentialUtils` to get the service
8989

9090
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
9191

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).
9299
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
93100
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
94101
- 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**:
152159

153160
Supplying the IAM API key:
154161

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+
155174
```java
156175
// letting the SDK manage the IAM token
157176
Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
@@ -168,6 +187,18 @@ Discovery service = new Discovery("2019-04-30", authenticator);
168187

169188
#### Username and password
170189

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+
171202
```java
172203
Authenticator authenticator = new BasicAuthenticator("<username>", "<password>");
173204
Discovery service = new Discovery("2019-04-30", authenticator);
@@ -190,6 +221,23 @@ service.configureClient(options);
190221
#### Cloud Pak for Data
191222
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.
192223

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+
193241
```java
194242
// letting the SDK manage the token
195243
Authenticator authenticator = new CloudPakForDataAuthenticator(

0 commit comments

Comments
 (0)