Skip to content

Commit 12c5598

Browse files
authored
Merge pull request #412 from watson-developer-cloud/update-authentication-instructions
Update readme with Allen's suggestions
2 parents db0d2a1 + 0e9da3c commit 12c5598

File tree

13 files changed

+76
-338
lines changed

13 files changed

+76
-338
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. 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

Scripts/Services/Assistant/v1/README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ You complete these steps to implement your application:
99

1010
* Develop your application. You code your application to connect to the Assistant workspace through API calls. You then integrate your app with other systems that you need, including back-end systems and third-party services such as chat services or social media.
1111

12-
### Instantiating and authenticating the service
13-
Before you can send requests to the service it must be instantiated and credentials must be set.
14-
```cs
15-
using IBM.Watson.DeveloperCloud.Services.Assistant.v1;
16-
using IBM.Watson.DeveloperCloud.Utilities;
17-
18-
void Start()
19-
{
20-
Credentials credentials = new Credentials(<username>, <password>, <url>);
21-
Assistant _assistant = new Assistant(credentials);
22-
}
23-
```
24-
25-
### Fail handler
26-
These examples use a common fail handler.
27-
```cs
28-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
29-
{
30-
Log.Error("ExampleAssistant.OnFail()", "Error received: {0}", error.ToString());
31-
}
32-
```
33-
3412
### Message
3513
Send a message to the Assistant instance
3614
```cs

Scripts/Services/Conversation/v1/README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,6 @@ You complete these steps to implement your application:
99

1010
* Develop your application. You code your application to connect to the Conversation workspace through API calls. You then integrate your app with other systems that you need, including back-end systems and third-party services such as chat services or social media.
1111

12-
### Instantiating and authenticating the service
13-
Before you can send requests to the service it must be instantiated and credentials must be set.
14-
```cs
15-
using IBM.Watson.DeveloperCloud.Services.Conversation.v1;
16-
using IBM.Watson.DeveloperCloud.Utilities;
17-
18-
void Start()
19-
{
20-
Credentials credentials = new Credentials(<username>, <password>, <url>);
21-
Conversation _conversation = new Conversation(credentials);
22-
}
23-
```
24-
25-
### Fail handler
26-
These examples use a common fail handler.
27-
```cs
28-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
29-
{
30-
Log.Error("ExampleConversation.OnFail()", "Error received: {0}", error.ToString());
31-
}
32-
```
33-
3412
### Message
3513
Send a message to the Conversation instance
3614
```cs

Scripts/Services/Discovery/v1/README.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,6 @@ The IBM Watson™ [Discovery][discovery] service makes it possible to rapidly bu
44
## Usage
55
The IBM Watson™ [Discovery][discovery] Service uses data analysis combined with cognitive intuition in order to take your unstructured data and enrich it so that you can query it to return the information that you need from it.
66

7-
### Instantiating and authenticating the service
8-
Before you can send requests to the service it must be instantiated and credentials must be set.
9-
```cs
10-
using IBM.Watson.DeveloperCloud.Services.Discovery.v1;
11-
using IBM.Watson.DeveloperCloud.Utilities;
12-
13-
void Start()
14-
{
15-
Credentials credentials = new Credentials(<username>, <password>, <url>);
16-
Discovery _discovery = new Discovery(credentials);
17-
}
18-
```
19-
20-
### Fail handler
21-
These examples use a common fail handler.
22-
```cs
23-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
24-
{
25-
Log.Error("ExampleDiscovery.OnFail()", "Error received: {0}", error.ToString());
26-
}
27-
```
28-
29-
30-
317
### Create an environment
328
Creates an environment for the service instance. Note: You can create only one environment per service instance. Attempting to create another environment for the same service instance results in an error. See the [Discovery service home page][discovery-sizing] for additional information about sizing and pricing. To create a free trial environment, specify the value of size as 0 (zero).
339
```cs

Scripts/Services/LanguageTranslator/v2/README.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,6 @@
77
## Usage
88
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
99

10-
### Instantiating and authenticating the service
11-
Before you can send requests to the service it must be instantiated and credentials must be set.
12-
```cs
13-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v2;
14-
using IBM.Watson.DeveloperCloud.Utilities;
15-
16-
void Start()
17-
{
18-
Credentials credentials = new Credentials(<username>, <password>, <url>);
19-
LanguageTranslator _languageTranslator = new LanguageTranslator(credentials);
20-
}
21-
```
22-
23-
24-
You can also authenticate the service with an IAM apikey
25-
```cs
26-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v2;
27-
using IBM.Watson.DeveloperCloud.Utilities;
28-
29-
void Start()
30-
{
31-
Runnable.Run(CreateService());
32-
}
33-
34-
IEnumerator CreateService()
35-
{
36-
TokenOptions tokenOptions = new TokenOptions()
37-
{
38-
IamApiKey = _iamApikey
39-
};
40-
41-
Credentials credentials = new Credentials(tokenOptions);
42-
43-
// Wait for tokendata
44-
while (!credentials.HasIamTokenData())
45-
yield return null;
46-
47-
LanguageTranslator _languageTranslator = new LanguageTranslator(credentials);
48-
}
49-
```
50-
51-
52-
### Fail handler
53-
These examples use a common fail handler.
54-
```cs
55-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
56-
{
57-
Log.Error("ExampleLanguageTranslatorV2.OnFail()", "Error received: {0}", error.ToString());
58-
}
59-
```
60-
61-
62-
6310
### List models
6411
Lists available models for language translation with option to filter by source or by target language.
6512
```cs

Scripts/Services/LanguageTranslator/v3/README.md

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -5,54 +5,6 @@
55
## Usage
66
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
77

8-
### Instantiating and authenticating the service
9-
Before you can send requests to the service it must be instantiated and credentials must be set.
10-
```cs
11-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v3;
12-
using IBM.Watson.DeveloperCloud.Utilities;
13-
14-
void Start()
15-
{
16-
Credentials credentials = new Credentials(<username>, <password>, <url>);
17-
LanguageTranslator _languageTranslator = new LanguageTranslator(credentials);
18-
}
19-
```
20-
21-
22-
You can also authenticate the service with an IAM apikey
23-
```cs
24-
using IBM.Watson.DeveloperCloud.Services.LanguageTranslator.v3;
25-
using IBM.Watson.DeveloperCloud.Utilities;
26-
27-
IEnumerator CreateService()
28-
{
29-
TokenOptions tokenOptions = new TokenOptions()
30-
{
31-
IamApiKey = _iamApikey
32-
};
33-
34-
Credentials credentials = new Credentials(tokenOptions);
35-
36-
// Wait for tokendata
37-
while (!credentials.HasIamTokenData())
38-
yield return null;
39-
40-
LanguageTranslator _languageTranslator = new LanguageTranslator("<versionDate>", credentials);
41-
}
42-
```
43-
44-
45-
### Fail handler
46-
These examples use a common fail handler.
47-
```cs
48-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
49-
{
50-
Log.Error("ExampleLanguageTranslatorV3V3.OnFail()", "Error received: {0}", error.ToString());
51-
}
52-
```
53-
54-
55-
568
### List models
579
Lists available models for language translation with option to filter by source or by target language.
5810
```cs

Scripts/Services/NaturalLanguageClassifier/v2/README.md

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,6 @@ Use [Natural Language Classifier][natural_language_classifier] service to create
55
## Usage
66
Classify intents in natural language.
77

8-
### Instantiating and authenticating the service
9-
Before you can send requests to the service it must be instantiated and credentials must be set.
10-
```cs
11-
using IBM.Watson.DeveloperCloud.Services.NaturalLanguageClassifier.v2;
12-
using IBM.Watson.DeveloperCloud.Utilities;
13-
14-
void Start()
15-
{
16-
Credentials credentials = new Credentials(<username>, <password>, <url>);
17-
NaturalLanguageClassifier _naturalLanguageClassifier = new NaturalLanguageClassifier(credentials);
18-
}
19-
```
20-
21-
22-
### Fail handler
23-
These examples use a common fail handler.
24-
```cs
25-
private void OnFail(RESTConnector.Error error, Dictionary<string, object> customData)
26-
{
27-
Log.Error("ExampleNaturalLanguageClassifier.OnFail()", "Error received: {0}", error.ToString());
28-
}
29-
```
30-
31-
328
### Listing Classifiers
339
Returns an empty array if no classifiers are available.
3410
```cs

0 commit comments

Comments
 (0)