Skip to content

Commit 00740d4

Browse files
authored
Merge pull request #254 from watson-developer-cloud/update-authentication-instructions
Update readme with Allen's suggestions
2 parents e98d4fc + 72b53e3 commit 00740d4

File tree

12 files changed

+71
-176
lines changed
  • src
    • IBM.WatsonDeveloperCloud.Assistant.v1
    • IBM.WatsonDeveloperCloud.Conversation.v1
    • IBM.WatsonDeveloperCloud.Discovery.v1
    • IBM.WatsonDeveloperCloud.LanguageTranslator.v2
    • IBM.WatsonDeveloperCloud.LanguageTranslator.v3
    • IBM.WatsonDeveloperCloud.NaturalLanguageClassifier.v1
    • IBM.WatsonDeveloperCloud.NaturalLanguageUnderstanding.v1
    • IBM.WatsonDeveloperCloud.PersonalityInsights.v3
    • IBM.WatsonDeveloperCloud.SpeechToText.v1
    • IBM.WatsonDeveloperCloud.ToneAnalyzer.v3
    • IBM.WatsonDeveloperCloud.VisualRecognition.v3

12 files changed

+71
-176
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. 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

src/IBM.WatsonDeveloperCloud.Assistant.v1/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ You complete these steps to implement your application:
2626

2727
* 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.
2828

29-
#### Instantiating and authenticating the service
30-
Before you can send requests to the service it must be instantiated and credentials must be set.
31-
```cs
32-
// create an Assistant Service instance
33-
AssistantService _assistant = new AssistantService();
34-
35-
// set the credentials
36-
_assistant.SetCredential(<username>, <password>);
37-
38-
// set the VersionDate
39-
_assistant.VersionDate = "<version-date>";
40-
```
41-
4229
#### List workspaces
4330
List existing workspaces for the service instance.
4431
```cs

src/IBM.WatsonDeveloperCloud.Conversation.v1/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,6 @@ You complete these steps to implement your application:
2626

2727
* 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.
2828

29-
#### Instantiating and authenticating the service
30-
Before you can send requests to the service it must be instantiated and credentials must be set.
31-
```cs
32-
// create a Conversation Service instance
33-
ConversationService _conversation = new ConversationService();
34-
35-
// set the credentials
36-
_conversation.SetCredential(<username>, <password>);
37-
38-
// set the VersionDate
39-
_conversation.VersionDate = "<version-date>";
40-
```
41-
4229
#### List workspaces
4330
List existing workspaces for the service instance.
4431
```cs

src/IBM.WatsonDeveloperCloud.Discovery.v1/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,6 @@ PM > Install-Package IBM.WatsonDeveloperCloud.Discovery.v1
2121
### Usage
2222
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.
2323

24-
#### Instantiating and authenticating the service
25-
Before you can send requests to the service it must be instantiated and credentials must be set.
26-
```cs
27-
// create a Discovery Service instance
28-
DiscoveryService _discovery = new DiscoveryService();
29-
30-
// set the credentials
31-
_discovery.SetCredential("<username>", "<password>");
32-
33-
// set the VersionDate
34-
_discovery.VersionDate = "<version-date>";
35-
```
36-
3724
#### Create an environment
3825
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).
3926
```cs

src/IBM.WatsonDeveloperCloud.LanguageTranslator.v2/README.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,6 @@ PM > Install-Package IBM.WatsonDeveloperCloud.LanguageTranslator.v2
2222
### Usage
2323
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
2424

25-
#### Instantiating and authenticating the service
26-
Before you can send requests to the service it must be instantiated and api key or access token must be set.
27-
```cs
28-
TokenOptions tokenOptions = new TokenOptions()
29-
{
30-
IamApiKey = "<iam-apikey>",
31-
IamAccessToken = "<iam-access-token>",
32-
IamUrl = "<service-endpoint>"
33-
};
34-
35-
var _languageTranslator = new LanguageTranslator(tokenOptions, "<version-date>");
36-
```
37-
38-
Services created before `2018-06-15` are authenticated using username and password.
39-
```cs
40-
// create a Language Translator Service instance
41-
LanguageTranslationService _languageTranslator = new LanguageTranslationService();
42-
43-
// set the credentials
44-
_languageTranslator.SetCredential("<username>", "<password>");
45-
```
46-
4725
#### Translate
4826
Translates input text from the source language to the target language.
4927
```cs

src/IBM.WatsonDeveloperCloud.LanguageTranslator.v3/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,6 @@ PM > Install-Package IBM.WatsonDeveloperCloud.LanguageTranslator.v3
2222
### Usage
2323
Select a domain, then identify or select the language of text, and then translate the text from one supported language to another.
2424

25-
#### Instantiating and authenticating the service
26-
Before you can send requests to the service it must be instantiated and api key or access token must be set.
27-
```cs
28-
TokenOptions tokenOptions = new TokenOptions()
29-
{
30-
IamApiKey = "<iam-apikey>",
31-
IamAccessToken = "<iam-access-token>",
32-
IamUrl = "<service-endpoint>"
33-
};
34-
35-
var _languageTranslator = new LanguageTranslator(tokenOptions, "<version-date>");
36-
```
37-
3825
#### Translate
3926
Translates input text from the source language to the target language.
4027
```cs

src/IBM.WatsonDeveloperCloud.NaturalLanguageClassifier.v1/README.md

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,6 @@ IBM Watson™ Natural Language Classifier can help your application understand t
2323

2424
You can create and train a classifier in less than 15 minutes.
2525

26-
#### Instantiating and authenticating the service
27-
Before you can send requests to the service it must be instantiated and api key or access token must be set.
28-
```cs
29-
TokenOptions tokenOptions = new TokenOptions()
30-
{
31-
IamApiKey = "<iam-apikey>",
32-
IamAccessToken = "<iam-access-token>",
33-
IamUrl = "<service-endpoint>"
34-
};
35-
36-
var _naturalLanguageClassifierService = new NaturalLanguageClassifierService(tokenOptions);
37-
38-
```
39-
40-
You can also authenticate using username and password.
41-
```cs
42-
// create a Natural Language Classifier Service instance
43-
NaturalLanguageClassifierService _naturalLanguageClassifierService = new NaturalLanguageClassifierService();
44-
45-
// set the credentials
46-
_naturalLanguageClassifierService.SetCredential("<username>", "<password>");
47-
```
48-
4926
#### Analyze
5027
Analyze features of natural language content.
5128
```cs

src/IBM.WatsonDeveloperCloud.NaturalLanguageUnderstanding.v1/README.md

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ Natural Language Understanding uses natural language processing to analyze seman
2323

2424
You can create [custom models][custom_models] with Watson Knowledge Studio that can be used to detect custom [entities][entities] and [relations][relations] in Natural Language Understanding.
2525

26-
#### Instantiating and authenticating the service
27-
Before you can send requests to the service it must be instantiated and credentials must be set.
28-
```cs
29-
// create a Natural Language Understanding Service instance
30-
NaturalLanguageUnderstandingService _naturalLanguageUnderstandingService = new NaturalLanguageUnderstandingService();
31-
32-
// set the credentials
33-
_naturalLanguageUnderstandingService.SetCredential("<username>", "<password>");
34-
35-
// set the VersionDate
36-
_naturalLanguageUnderstandingService.VersionDate = "2017-02-27";
37-
```
38-
3926
#### Analyze
4027
Analyze features of natural language content.
4128
```cs

src/IBM.WatsonDeveloperCloud.PersonalityInsights.v3/README.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ PM > Install-Package IBM.WatsonDeveloperCloud.PersonalityInsights.v3
2626
### Usage
2727
The service offers a single `profile` method that accepts up to 20 MB of input data and produces results in JSON or CSV format. The service accepts input in Arabic, English, Japanese, or Spanish and can produce output in a variety of languages.
2828

29-
#### Instantiating and authenticating the service
30-
Before you can send requests to the service it must be instantiated and credentials must be set.
31-
```cs
32-
// create a Personality Insights Service instance
33-
PersonalityInsightsService _personalityInsights = new PersonalityInsightsService();
34-
35-
// set the credentials
36-
_personalityInsights.SetCredential("<username>", "<password>");
37-
```
38-
3929
#### Profile
4030
Extract personality characteristics based on how a person writes.
4131
```cs

src/IBM.WatsonDeveloperCloud.SpeechToText.v1/README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,7 @@ The Speech to Text API consists of the following groups of related calls:
3737
* Custom corpora provides an HTTP interface for managing the corpora associated with a custom language model. You add a corpus to a custom model to extract words from the corpus into the model's vocabulary.
3838

3939
* Custom words provides an HTTP interface for managing individual words in a custom language model. You can add, list, and delete words from a custom model.
40-
41-
#### Instantiating and authenticating the service
42-
Before you can send requests to the service it must be instantiated and credentials must be set.
43-
```cs
44-
// create a Speech to Text Service instance
45-
SpeechToTextService _speechToText = new SpeechToTextService();
46-
47-
// set the credentials
48-
_speechToText.SetCredential("<username>", "<password>");
49-
```
50-
40+
*
5141
#### Get models
5242
Retrieves a list of all models available for use with the service. The information includes the name of the model and its minimum sampling rate in Hertz, among other things.
5343
```cs

0 commit comments

Comments
 (0)