Skip to content

Commit 817f3ba

Browse files
committed
feat(Examples): Removed CF authentication and IamUrl from the service examples.
1 parent 266801e commit 817f3ba

13 files changed

+171
-349
lines changed

Examples/ServiceExamples/Scripts/ExampleAssistantV1.cs

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,10 @@ public class ExampleAssistantV1 : MonoBehaviour
3737
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
3838
[SerializeField]
3939
private string _versionDate;
40-
[Header("CF Authentication")]
41-
[Tooltip("The authentication username.")]
42-
[SerializeField]
43-
private string _username;
44-
[Tooltip("The authentication password.")]
45-
[SerializeField]
46-
private string _password;
4740
[Header("IAM Authentication")]
4841
[Tooltip("The IAM apikey.")]
4942
[SerializeField]
5043
private string _iamApikey;
51-
[Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
52-
[SerializeField]
53-
private string _iamUrl;
5444
#endregion
5545

5646
private string _createdWorkspaceId;
@@ -132,32 +122,25 @@ void Start()
132122

133123
private IEnumerator CreateService()
134124
{
135-
// Create credential and instantiate service
136-
Credentials credentials = null;
137-
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
125+
if(string.IsNullOrEmpty(_iamApikey))
138126
{
139-
// Authenticate using username and password
140-
credentials = new Credentials(_username, _password, _serviceUrl);
127+
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
141128
}
142-
else if (!string.IsNullOrEmpty(_iamApikey))
143-
{
144-
// Authenticate using iamApikey
145-
TokenOptions tokenOptions = new TokenOptions()
146-
{
147-
IamApiKey = _iamApikey,
148-
IamUrl = _iamUrl
149-
};
150-
151-
credentials = new Credentials(tokenOptions, _serviceUrl);
152-
153-
// Wait for tokendata
154-
while (!credentials.HasIamTokenData())
155-
yield return null;
156-
}
157-
else
129+
130+
// Create credential and instantiate service
131+
Credentials credentials = null;
132+
133+
// Authenticate using iamApikey
134+
TokenOptions tokenOptions = new TokenOptions()
158135
{
159-
throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
160-
}
136+
IamApiKey = _iamApikey
137+
};
138+
139+
credentials = new Credentials(tokenOptions, _serviceUrl);
140+
141+
// Wait for tokendata
142+
while (!credentials.HasIamTokenData())
143+
yield return null;
161144

162145
_service = new Assistant(credentials);
163146
_service.VersionDate = _versionDate;

Examples/ServiceExamples/Scripts/ExampleAssistantV2.cs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,10 @@ public class ExampleAssistantV2 : MonoBehaviour
3838
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
3939
[SerializeField]
4040
private string _versionDate;
41-
[Header("CF Authentication")]
42-
[Tooltip("The authentication username.")]
43-
[SerializeField]
44-
private string _username;
45-
[Tooltip("The authentication password.")]
46-
[SerializeField]
47-
private string _password;
4841
[Header("IAM Authentication")]
4942
[Tooltip("The IAM apikey.")]
5043
[SerializeField]
5144
private string _iamApikey;
52-
[Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
53-
[SerializeField]
54-
private string _iamUrl;
5545
#endregion
5646

5747
private Assistant _service;
@@ -73,32 +63,25 @@ private void Start()
7363

7464
private IEnumerator CreateService()
7565
{
76-
// Create credential and instantiate service
77-
Credentials credentials = null;
78-
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
66+
if (string.IsNullOrEmpty(_iamApikey))
7967
{
80-
// Authenticate using username and password
81-
credentials = new Credentials(_username, _password, _serviceUrl);
68+
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
8269
}
83-
else if (!string.IsNullOrEmpty(_iamApikey))
84-
{
85-
// Authenticate using iamApikey
86-
TokenOptions tokenOptions = new TokenOptions()
87-
{
88-
IamApiKey = _iamApikey,
89-
IamUrl = _iamUrl
90-
};
9170

92-
credentials = new Credentials(tokenOptions, _serviceUrl);
71+
// Create credential and instantiate service
72+
Credentials credentials = null;
9373

94-
// Wait for tokendata
95-
while (!credentials.HasIamTokenData())
96-
yield return null;
97-
}
98-
else
74+
// Authenticate using iamApikey
75+
TokenOptions tokenOptions = new TokenOptions()
9976
{
100-
throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
101-
}
77+
IamApiKey = _iamApikey
78+
};
79+
80+
credentials = new Credentials(tokenOptions, _serviceUrl);
81+
82+
// Wait for tokendata
83+
while (!credentials.HasIamTokenData())
84+
yield return null;
10285

10386
_service = new Assistant(credentials);
10487
_service.VersionDate = _versionDate;

Examples/ServiceExamples/Scripts/ExampleCompareComplyV1.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ void Start()
7272

7373
private IEnumerator CreateService()
7474
{
75+
if (string.IsNullOrEmpty(_iamApikey))
76+
{
77+
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
78+
}
79+
7580
// Create credential and instantiate service
7681
Credentials credentials = null;
7782
// Authenticate using iamApikey

Examples/ServiceExamples/Scripts/ExampleConversation.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ public class ExampleConversation : MonoBehaviour
4848
[Tooltip("The IAM apikey.")]
4949
[SerializeField]
5050
private string _iamApikey;
51-
[Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
52-
[SerializeField]
53-
private string _iamUrl;
5451
#endregion
5552

5653
private Conversation _service;
@@ -81,8 +78,7 @@ private IEnumerator CreateService()
8178
// Authenticate using iamApikey
8279
TokenOptions tokenOptions = new TokenOptions()
8380
{
84-
IamApiKey = _iamApikey,
85-
IamUrl = _iamUrl
81+
IamApiKey = _iamApikey
8682
};
8783

8884
credentials = new Credentials(tokenOptions, _serviceUrl);

Examples/ServiceExamples/Scripts/ExampleDiscovery.cs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,10 @@ public class ExampleDiscovery : MonoBehaviour
3434
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
3535
[SerializeField]
3636
private string _versionDate;
37-
[Header("CF Authentication")]
38-
[Tooltip("The authentication username.")]
39-
[SerializeField]
40-
private string _username;
41-
[Tooltip("The authentication password.")]
42-
[SerializeField]
43-
private string _password;
4437
[Header("IAM Authentication")]
4538
[Tooltip("The IAM apikey.")]
4639
[SerializeField]
4740
private string _iamApikey;
48-
[Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
49-
[SerializeField]
50-
private string _iamUrl;
5141
#endregion
5242

5343
private Discovery _service;
@@ -110,32 +100,25 @@ private void Start()
110100

111101
private IEnumerator CreateService()
112102
{
113-
// Create credential and instantiate service
114-
Credentials credentials = null;
115-
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
103+
if (string.IsNullOrEmpty(_iamApikey))
116104
{
117-
// Authenticate using username and password
118-
credentials = new Credentials(_username, _password, _serviceUrl);
105+
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
119106
}
120-
else if (!string.IsNullOrEmpty(_iamApikey))
107+
108+
// Create credential and instantiate service
109+
Credentials credentials = null;
110+
111+
// Authenticate using iamApikey
112+
TokenOptions tokenOptions = new TokenOptions()
121113
{
122-
// Authenticate using iamApikey
123-
TokenOptions tokenOptions = new TokenOptions()
124-
{
125-
IamApiKey = _iamApikey,
126-
IamUrl = _iamUrl
127-
};
114+
IamApiKey = _iamApikey
115+
};
128116

129-
credentials = new Credentials(tokenOptions, _serviceUrl);
117+
credentials = new Credentials(tokenOptions, _serviceUrl);
130118

131-
// Wait for tokendata
132-
while (!credentials.HasIamTokenData())
133-
yield return null;
134-
}
135-
else
136-
{
137-
throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
138-
}
119+
// Wait for tokendata
120+
while (!credentials.HasIamTokenData())
121+
yield return null;
139122

140123
_service = new Discovery(credentials);
141124
_service.VersionDate = _versionDate;

Examples/ServiceExamples/Scripts/ExampleLanguageTranslatorV3.cs

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,10 @@ public class ExampleLanguageTranslatorV3 : MonoBehaviour
3333
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
3434
[SerializeField]
3535
private string _versionDate;
36-
[Header("CF Authentication")]
37-
[Tooltip("The authentication username.")]
38-
[SerializeField]
39-
private string _username;
40-
[Tooltip("The authentication password.")]
41-
[SerializeField]
42-
private string _password;
4336
[Header("IAM Authentication")]
4437
[Tooltip("The IAM apikey.")]
4538
[SerializeField]
4639
private string _iamApikey;
47-
[Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
48-
[SerializeField]
49-
private string _iamUrl;
5040
#endregion
5141

5242
private string _pharseToTranslate = "Hello, welcome to IBM Watson!";
@@ -75,32 +65,25 @@ void Start()
7565

7666
private IEnumerator CreateService()
7767
{
78-
// Create credential and instantiate service
79-
Credentials credentials = null;
80-
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
81-
{
82-
// Authenticate using username and password
83-
credentials = new Credentials(_username, _password, _serviceUrl);
84-
}
85-
else if (!string.IsNullOrEmpty(_iamApikey))
68+
if (string.IsNullOrEmpty(_iamApikey))
8669
{
87-
// Authenticate using iamApikey
88-
TokenOptions tokenOptions = new TokenOptions()
89-
{
90-
IamApiKey = _iamApikey,
91-
IamUrl = _iamUrl
92-
};
93-
94-
credentials = new Credentials(tokenOptions, _serviceUrl);
95-
96-
// Wait for tokendata
97-
while (!credentials.HasIamTokenData())
98-
yield return null;
70+
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
9971
}
100-
else
72+
73+
// Create credential and instantiate service
74+
Credentials credentials = null;
75+
76+
// Authenticate using iamApikey
77+
TokenOptions tokenOptions = new TokenOptions()
10178
{
102-
throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
103-
}
79+
IamApiKey = _iamApikey
80+
};
81+
82+
credentials = new Credentials(tokenOptions, _serviceUrl);
83+
84+
// Wait for tokendata
85+
while (!credentials.HasIamTokenData())
86+
yield return null;
10487

10588
_service = new LanguageTranslator(_versionDate, credentials);
10689

Examples/ServiceExamples/Scripts/ExampleNaturalLanguageClassifier.cs

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,10 @@ public class ExampleNaturalLanguageClassifier : MonoBehaviour
4040
[Tooltip("The version date with which you would like to use the service in the form YYYY-MM-DD.")]
4141
[SerializeField]
4242
private string _versionDate;
43-
[Header("CF Authentication")]
44-
[Tooltip("The authentication username.")]
45-
[SerializeField]
46-
private string _username;
47-
[Tooltip("The authentication password.")]
48-
[SerializeField]
49-
private string _password;
5043
[Header("IAM Authentication")]
5144
[Tooltip("The IAM apikey.")]
5245
[SerializeField]
5346
private string _iamApikey;
54-
[Tooltip("The IAM url used to authenticate the apikey (optional). This defaults to \"https://iam.bluemix.net/identity/token\".")]
55-
[SerializeField]
56-
private string _iamUrl;
5747
#endregion
5848

5949
private NaturalLanguageClassifier _service;
@@ -83,32 +73,25 @@ void Start()
8373

8474
private IEnumerator CreateService()
8575
{
86-
// Create credential and instantiate service
87-
Credentials credentials = null;
88-
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_password))
76+
if (string.IsNullOrEmpty(_iamApikey))
8977
{
90-
// Authenticate using username and password
91-
credentials = new Credentials(_username, _password, _serviceUrl);
78+
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
9279
}
93-
else if (!string.IsNullOrEmpty(_iamApikey))
80+
81+
// Create credential and instantiate service
82+
Credentials credentials = null;
83+
84+
// Authenticate using iamApikey
85+
TokenOptions tokenOptions = new TokenOptions()
9486
{
95-
// Authenticate using iamApikey
96-
TokenOptions tokenOptions = new TokenOptions()
97-
{
98-
IamApiKey = _iamApikey,
99-
IamUrl = _iamUrl
100-
};
87+
IamApiKey = _iamApikey
88+
};
10189

102-
credentials = new Credentials(tokenOptions, _serviceUrl);
90+
credentials = new Credentials(tokenOptions, _serviceUrl);
10391

104-
// Wait for tokendata
105-
while (!credentials.HasIamTokenData())
106-
yield return null;
107-
}
108-
else
109-
{
110-
throw new WatsonException("Please provide either username and password or IAM apikey to authenticate the service.");
111-
}
92+
// Wait for tokendata
93+
while (!credentials.HasIamTokenData())
94+
yield return null;
11295

11396
_service = new NaturalLanguageClassifier(credentials);
11497

0 commit comments

Comments
 (0)