Skip to content

Commit f2133a0

Browse files
committed
Update readme with clearer instructions on authentication
1 parent e98d4fc commit f2133a0

File tree

1 file changed

+70
-18
lines changed

1 file changed

+70
-18
lines changed

README.md

Lines changed: 70 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,76 @@ You can get the latest SDK packages through NuGet. Installation instructions can
3939

4040
Or manually [here][latest_release].
4141

42+
## Authentication
43+
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
44+
45+
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
46+
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
47+
- Visual Recognition uses a form of [API key](#api-key) only with instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
48+
49+
### Getting credentials
50+
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:
51+
52+
1. Go to the IBM Cloud **[Dashboard][watson-dashboard]** page.
53+
1. Either click an existing Watson service instance or click **Create**.
54+
1. Click **Show** to view your service credentials.
55+
1. Copy the `url` and either `apikey` or `username` and `password`.
56+
57+
In your code, you can use these values in the service constructor or with a method call after instantiating your service.
58+
59+
### IAM
60+
61+
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.
62+
63+
You supply either an IAM service **API key** or an **access token**:
64+
65+
- 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.
66+
- Use the access token if you want to manage the lifecycle yourself. Access tokens are valid. 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.
67+
68+
#### Supplying the IAM API key
69+
```cs
70+
void Example()
71+
{
72+
TokenOptions iamAssistantTokenOptions = new TokenOptions()
73+
{
74+
IamApiKey = "<iam-apikey>",
75+
IamUrl = "<service-endpoint>"
76+
};
77+
78+
_assistant = new AssistantService(iamAssistantTokenOptions, "<version-date>");
79+
}
80+
```
81+
82+
#### Supplying the access token
83+
```cs
84+
void Example()
85+
{
86+
TokenOptions iamAssistantTokenOptions = new TokenOptions()
87+
{
88+
IamAccessToken = "<iam-access-token>"
89+
};
90+
91+
_assistant = new AssistantService(iamAssistantTokenOptions, "<version-date>");
92+
}
93+
```
94+
95+
### Username and password
96+
```cs
97+
void Example()
98+
{
99+
_assistant = new AssistantService("<username>", "<password>", "<version-date>");
100+
}
101+
```
102+
103+
### API key
104+
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
105+
```cs
106+
void Example()
107+
{
108+
_visualRecognition = new VisualRecognitionService("<apikey>", "<version-date>");
109+
}
110+
```
111+
42112
## Custom Request Headers
43113
You can send custom request headers by adding them to the `customData` object.
44114
```cs
@@ -72,24 +142,6 @@ void Example()
72142
}
73143
```
74144

75-
## IAM Authentication
76-
You can authenticate using IAM rather than username and password or apikey. You can either allow the SDK to manage the token by providing your IAM apikey or manage the token yourself by providing an access token.
77-
```cs
78-
void Example()
79-
{
80-
// Provide either an iamApiKey or iamAccessToken to authenticate the service.
81-
TokenOptions iamAssistantTokenOptions = new TokenOptions()
82-
{
83-
IamApiKey = "<iam-apikey>",
84-
IamAccessToken = "<iam-access-token>",
85-
IamUrl = "<service-endpoint>"
86-
};
87-
88-
_assistant = new AssistantService(iamAssistantTokenOptions, "<version-date>");
89-
var results = assistant.Message("<workspace-id>", "<message-request>");
90-
}
91-
```
92-
93145
## Documentation
94146
Click [here][dotnet-standard-sdk-documentation] for documentation by release and branch.
95147

0 commit comments

Comments
 (0)