You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47-7Lines changed: 47 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,15 +141,53 @@ Watson services are migrating to token-based Identity and Access Management (IAM
141
141
**Note:** Previously, it was possible to authenticate using a token in a header called `X-Watson-Authorization-Token`. This method is deprecated. The token continues to work with Cloud Foundry services, but is not supported for services that use Identity and Access Management (IAM) authentication. See [here](#iam) for details.
142
142
143
143
### Getting credentials
144
+
144
145
To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:
145
146
146
-
1. Go to the IBM Cloud [Dashboard](https://console.bluemix.net/dashboard/apps?category=ai) page.
147
-
1. Either click an existing Watson service instance or click [**Create resource > AI**](https://console.bluemix.net/catalog/?category=ai) and create a service instance.
148
-
1. Copy the credentials you need for authentication. Click **Show** if the credentials are masked.
147
+
1. Go to the IBM Cloud [Dashboard](https://cloud.ibm.com/) page.
148
+
1. Either click an existing Watson service instance in your [resource list](https://cloud.ibm.com/resources) or click [**Create resource > AI**](https://cloud.ibm.com/catalog?category=ai) and create a service instance.
149
+
1. Click on the **Manage** item in the left nav bar of your service instance.
150
+
151
+
On this page, you should be able to see your credentials for accessing your service instance.
149
152
150
153
In your code, you can use these values in the service constructor or with a method call after instantiating your service.
151
154
152
-
### IAM
155
+
### Supplying credentials
156
+
157
+
There are two ways to supply the credentials you found above to the SDK for authentication.
158
+
159
+
#### Credential file (easier!)
160
+
161
+
With a credential file, you just need to put the file in the right place and the SDK will do the work of parsing it and authenticating. You can get this file by clicking the **Download** button for the credentials in the **Manage** tab of your service instance.
162
+
163
+
The file downloaded will be called `ibm-credentials.env`. This is the name the SDK will search for and **must** be preserved unless you want to configure the file path (more on that later). The SDK will look for your `ibm-credentials.env` file in the following places (in order):
164
+
165
+
- Your system's home directory
166
+
- The top-level directory of the project you're using the SDK in
167
+
168
+
As long as you set that up correctly, you don't have to worry about setting any authentication options in your code. So, for example, if you created and downloaded the credential file for your Discovery instance, you just need to do the following:
169
+
170
+
```java
171
+
Discovery service =newDiscovery("2017-11-07");
172
+
```
173
+
174
+
And that's it!
175
+
176
+
If you're using more than one service at a time in your code and get two different `ibm-credentials.env` files, just put the contents together in one `ibm-credentials.env` file and the SDK will handle assigning credentials to their appropriate services.
177
+
178
+
If you would like to configure the location/name of your credential file, you can set an environment variable called `IBM_CREDENTIALS_FILE`. **This will take precedence over the locations specified above.** Here's how you can do that:
179
+
180
+
```bash
181
+
export IBM_CREDENTIALS_FILE="<path>"
182
+
```
183
+
184
+
where `<path>` is something like `/home/user/Downloads/<file_name>.env`.
185
+
186
+
#### Manually
187
+
188
+
If you'd prefer to set authentication values manually in your code, the SDK supports that as well. The way you'll do this depends on what type of credentials your service instance gives you.
189
+
190
+
##### IAM
153
191
154
192
Some services use token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.
155
193
@@ -159,7 +197,8 @@ You supply either an IAM service **API key** or an **access token**:
159
197
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://console.bluemix.net/docs/services/watson/getting-started-iam.html). If you want to switch to API key, override your stored IAM credentials with an IAM API key. Then call the `setIamCredentials()` method again.
160
198
161
199
162
-
#### Supplying the IAM API key
200
+
Supplying the IAM API key:
201
+
163
202
```java
164
203
// in the constructor, letting the SDK manage the IAM token
165
204
IamOptions options =newIamOptions.Builder()
@@ -178,7 +217,8 @@ IamOptions options = new IamOptions.Builder()
178
217
service.setIamCredentials(options);
179
218
```
180
219
181
-
#### Supplying the access token
220
+
Supplying the access token:
221
+
182
222
```java
183
223
// in the constructor, assuming control of managing IAM token
184
224
IamOptions options =newIamOptions.Builder()
@@ -196,7 +236,7 @@ IamOptions options = new IamOptions.Builder()
0 commit comments