Skip to content

Commit 11935d3

Browse files
committed
Update readme with Allen's suggestions
1 parent db0d2a1 commit 11935d3

File tree

1 file changed

+76
-26
lines changed

1 file changed

+76
-26
lines changed

README.md

Lines changed: 76 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,50 +75,44 @@ To get started with the Watson Services in Unity, click on each service below to
7575
* [Visual Recognition](/Scripts/Services/VisualRecognition/v3)
7676

7777
## Authentication
78-
Before you can use a service, it must be authenticated with the service instance's `username`, `password` and `url`.
78+
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
7979

80-
```cs
81-
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
82-
using IBM.Watson.DeveloperCloud.Utilities;
80+
- 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).
8383

84-
void Start()
85-
{
86-
Credentials credentials = new Credentials(<username>, <password>, <url>);
87-
Assistant _assistant = new Assistant(credentials);
88-
}
89-
```
84+
### Getting credentials
85+
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:
9086

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`.
9291

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.
9493

95-
```cs
96-
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
97-
using IBM.Watson.DeveloperCloud.Utilities;
94+
### IAM
9895

99-
void Start()
100-
{
101-
Credentials credentials = new Credentials(<apikey>, <url>);
102-
VisualRecognition _visualRecognition = new VisualRecognition(credentials);
103-
}
104-
```
96+
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**:
10599

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`.
107102

103+
#### Supplying the IAM API key
108104
```cs
109-
void IEnumerator TokenExample()
105+
IEnumerator TokenExample()
110106
{
111107
// Create IAM token options and supply the apikey.
112-
// Alternatively you can supply an access token.
113108
TokenOptions iamTokenOptions = new TokenOptions()
114109
{
115110
IamApiKey = "<iam-api-key>",
116-
IamAccessToken = "<iam-access-token>",
117111
IamUrl = "<service-url>"
118112
};
119113

120114
// Create credentials using the IAM token options
121-
_credentials = new Credentials(iamTokenOptions, "<service-url");
115+
_credentials = new Credentials(iamTokenOptions, "<service-url");
122116
while (!_credentials.HasIamTokenData())
123117
yield return null;
124118

@@ -138,6 +132,61 @@ private void OnFail(RESTConnector.Error error, Dictionary<string, object> custom
138132
}
139133
```
140134

135+
#### Supplying the access token
136+
```cs
137+
void TokenExample()
138+
{
139+
// Create IAM token options and supply the access token.
140+
TokenOptions iamTokenOptions = new TokenOptions()
141+
{
142+
IamAccessToken = "<iam-access-token>"
143+
};
144+
145+
// Create credentials using the IAM token options
146+
_credentials = new Credentials(iamTokenOptions, "<service-url");
147+
148+
_assistant = new Assistant(_credentials);
149+
_assistant.VersionDate = "2018-02-16";
150+
_assistant.ListWorkspaces(OnListWorkspaces, OnFail);
151+
}
152+
153+
private void OnListWorkspaces(WorkspaceCollection response, Dictionary<string, object> customData)
154+
{
155+
Log.Debug("OnListWorkspaces()", "Response: {0}", customData["json"].ToString());
156+
}
157+
158+
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
159+
{
160+
Log.Debug("OnFail()", "Failed: {0}", error.ToString());
161+
}
162+
```
163+
164+
### Username and password
165+
```cs
166+
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
167+
using IBM.Watson.DeveloperCloud.Utilities;
168+
169+
void Start()
170+
{
171+
Credentials credentials = new Credentials(<username>, <password>, <url>);
172+
Assistant _assistant = new Assistant(credentials);
173+
}
174+
```
175+
176+
### API key
177+
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
178+
```cs
179+
using IBM.Watson.DeveloperCloud.Services.VisualRecognition.v3;
180+
using IBM.Watson.DeveloperCloud.Utilities;
181+
182+
void Start()
183+
{
184+
Credentials credentials = new Credentials(<apikey>, <url>);
185+
VisualRecognition _visualRecognition = new VisualRecognition(credentials);
186+
}
187+
```
188+
189+
141190
## Callbacks
142191
Success and failure callbacks are required. You can specify the return type in the callback.
143192
```cs
@@ -324,3 +373,4 @@ See [CONTRIBUTING.md](.github/CONTRIBUTING.md).
324373
[ibm_cloud_registration]: http://console.bluemix.net/registration?cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Unity
325374
[get_unity]: https://unity3d.com/get-unity
326375
[documentation]: https://watson-developer-cloud.github.io/unity-sdk/
376+
[watson-dashboard]: https://console.bluemix.net/dashboard/apps?category=watson

0 commit comments

Comments
 (0)