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
+48-7Lines changed: 48 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -85,14 +85,55 @@ Watson services are migrating to token-based Identity and Access Management (IAM
85
85
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
86
86
87
87
### Getting credentials
88
+
88
89
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:
89
90
90
-
1. Go to the IBM Cloud [Dashboard](https://console.bluemix.net/dashboard/apps?category=ai) page.
91
-
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.
92
-
1. Click **Show** to view your service credentials.
93
-
1. Copy the `url` and either `apikey` or `username` and `password`.
91
+
1. Go to the IBM Cloud [Dashboard](https://cloud.ibm.com/) page.
92
+
2. 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.
93
+
3. Click on the **Manage** item in the left nav bar of your service instance.
94
+
95
+
On this page, you should be able to see your credentials for accessing your service instance.
96
+
97
+
In your code, you can use these values in the service constructor or with a method call after instantiating your service.
98
+
99
+
### Supplying credentials
100
+
101
+
There are two ways to supply the credentials you found above to the SDK for authentication:
102
+
103
+
#### Credentials file (easier!)
104
+
105
+
With a credentials 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.
106
+
107
+
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):
108
+
109
+
- Directory provided by the environment variable `IBM_CREDENTIALS_FILE`
110
+
- Your system's home directory
111
+
- Your current working directory (the directory Node is executed from)
112
+
113
+
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:
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.
123
+
124
+
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:
125
+
126
+
```bash
127
+
export IBM_CREDENTIALS_FILE="<path>"
128
+
```
129
+
130
+
where `<path>` is something like `/home/user/Downloads/<file_name>.env`. If you just provide a path to a directory, the SDK will look for a file called `ibm-credentials.env` in that directory.
131
+
132
+
#### Manually
133
+
134
+
The SDK also supports setting credentials manually in your code. You will either use IAM credentials or Basic Authentication (username/password) credentials.
94
135
95
-
### IAM
136
+
#####IAM
96
137
97
138
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.
98
139
@@ -101,7 +142,7 @@ You supply either an IAM service **API key** or an **access token**:
101
142
- Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
102
143
- 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.
103
144
104
-
#### Supplying the IAM API key
145
+
######Supplying the IAM API key
105
146
106
147
```js
107
148
// in the constructor, letting the SDK manage the IAM token
@@ -113,7 +154,7 @@ const discovery = new DiscoveryV1({
113
154
});
114
155
```
115
156
116
-
#### Supplying the access token
157
+
######Supplying the access token
117
158
118
159
```js
119
160
// in the constructor, assuming control of managing IAM token
0 commit comments