Skip to content

Commit 663ff04

Browse files
committed
docs: Added documentation for ibm-credentials.env
1 parent 01e5f55 commit 663ff04

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,50 @@ void UsernamePasswordExample()
185185
}
186186
```
187187

188+
### Supplying credentials
189+
190+
There are two ways to supply the credentials you found above to the SDK for authentication.
191+
192+
#### Credential file (easier!)
193+
194+
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.
195+
196+
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):
197+
198+
- Your system's home directory
199+
- The top-level directory of the project you're using the SDK in
200+
201+
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:
202+
203+
```cs
204+
public IEnumerator ExampleAutoService()
205+
{
206+
Assistant assistantService = new Assistant("2019-04-03");
207+
208+
// Wait for authorization token
209+
while (!assistantService.Credentials.HasIamTokenData())
210+
yield return null;
211+
212+
var listWorkspacesResult = assistantService.ListWorkspaces();
213+
}
214+
```
215+
216+
And that's it!
217+
218+
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.
219+
220+
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:
221+
222+
```bash
223+
export IBM_CREDENTIALS_FILE="<path>"
224+
```
225+
226+
where `<path>` is something like `/home/user/Downloads/<file_name>.env`.
227+
228+
#### Manually
229+
230+
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.
231+
188232
## Callbacks
189233
A success callback is required. You can specify the return type in the callback.
190234
```cs

0 commit comments

Comments
 (0)