Skip to content

Commit e6fbdeb

Browse files
committed
add iam section to readme
1 parent ec4a652 commit e6fbdeb

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

README.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Node.js client library to use the Watson APIs.
2121
* [Examples](#examples)
2222
* [IBM Watson Services](#ibm-watson-services)
2323
* [Authorization](#authorization)
24-
* [Assistant]
24+
* [Assistant] (#assistant)
2525
* [Discovery](#discovery)
2626
* [Language Translator](#language-translator)
2727
* [Natural Language Classifier](#natural-language-classifier)
@@ -46,7 +46,7 @@ npm install watson-developer-cloud
4646
```
4747

4848
## Getting the service credentials
49-
49+
### Basic Auth (or API key for Visual Recognition)
5050
You will need the `username`, `password`, and `url` (`api_key` for Visual Recognition) for each service. Service credentials are different from your IBM Cloud account username and password.
5151

5252
To get your service credentials, follow these steps:
@@ -59,6 +59,43 @@ To get your service credentials, follow these steps:
5959
1. Click **View credentials** under **Actions**.
6060
1. Copy `username`, `password` (or `api_key` for Visual Recognition), and `url`.
6161

62+
### IAM
63+
64+
When authenticating with IAM, you have the option of passing in:
65+
- the IAM API key and, optionally, the IAM service URL
66+
- an IAM access token
67+
68+
**Be aware that passing in an access token means that you're assuming responsibility for maintaining that token's lifecycle.** If you instead pass in an IAM API key, the SDK will manage it for you.
69+
70+
```js
71+
// in the constructor, letting the SDK manage the IAM token
72+
const discovery = new DiscoveryV1({
73+
url: '<service_url>',
74+
version: '<version-date>',
75+
iam_apikey: '<iam_api_key>',
76+
iam_url: '<iam_url>', // optional - the default value is https://iam.ng.bluemix.net/identity/token
77+
});
78+
```
79+
80+
```js
81+
// in the constructor, assuming control of managing IAM token
82+
const discovery = new DiscoveryV1({
83+
url: '<service_url>',
84+
version: '<version-date>',
85+
iam_access_token: '<access-token>'
86+
});
87+
```
88+
89+
```js
90+
// after instantiation, assuming control of managing IAM token
91+
const discovery = new DiscoveryV1({
92+
url: '<service_url>',
93+
version: '<version-date>'
94+
});
95+
96+
discovery.setAccessToken('<access-token>')
97+
```
98+
6299
## Usage
63100

64101
The examples below assume that you already have service credentials. If not,
@@ -71,7 +108,9 @@ Credentials are checked for in the following order:
71108

72109
1. Hard-coded or programatic credentials passed to the service constructor
73110

74-
2. `SERVICE_NAME_USERNAME` and `SERVICE_NAME_PASSWORD` environment properties (or `SERVICE_NAME_API_KEY` when appropriate) and, optionally, `SERVICE_NAME_URL`
111+
2. Environment variables:
112+
- `SERVICE_NAME_USERNAME` and `SERVICE_NAME_PASSWORD` environment properties (or `SERVICE_NAME_API_KEY` when appropriate) and, optionally, `SERVICE_NAME_URL`
113+
- If using IAM: `SERVICE_NAME_IAM_APIKEY` and optionally `SERVICE_NAME_IAM_URL`, or `SERVICE_NAME_IAM_ACCESS_TOKEN`
75114

76115
3. IBM-Cloud-supplied credentials (via the `VCAP_SERVICES` JSON-encoded environment property)
77116

0 commit comments

Comments
 (0)