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
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
81
+
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
82
+
- 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).
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:
90
86
91
-
For services that authenticate using an apikey, you can instantiate the service instance using a `Credential` object with an `apikey` and `url`.
87
+
1. Go to the IBM Cloud **[Dashboard][watson-dashboard]** page.
88
+
1. Either click an existing Watson service instance or click **Create**.
89
+
1. Click **Show** to view your service credentials.
90
+
1. Copy the `url` and either `apikey` or `username` and `password`.
92
91
93
-
**Important**: Instantiation with `apikey` works only with Visual Recognition service instances created before May 23, 2018. Visual Recognition instances created after May 22 use IAM.
92
+
In your code, you can use these values in the service constructor or with a method call after instantiating your service.
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.
97
+
98
+
You supply either an IAM service **API key** or an **access token**:
105
99
106
-
You can also authenticate a service using IAM authentication. You can either supply a valid access token in the `iamTokenOptions` or get an access token using an `apikey`.
100
+
- 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.
101
+
- 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, in a coroutine, override your stored IAM credentials with an IAM API key and yield until the credentials object `HasIamTokenData()` returns `true`.
107
102
103
+
#### Supplying the IAM API key
108
104
```cs
109
-
voidIEnumeratorTokenExample()
105
+
IEnumeratorTokenExample()
110
106
{
111
107
// Create IAM token options and supply the apikey.
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
0 commit comments