18
18
using System . Collections . Generic ;
19
19
using System . Text ;
20
20
using IBM . Cloud . SDK ;
21
+ using IBM . Cloud . SDK . Authentication ;
21
22
using IBM . Cloud . SDK . Connection ;
22
23
using IBM . Cloud . SDK . Utilities ;
23
24
using IBM . Watson . Assistant . V2 . Model ;
@@ -33,20 +34,16 @@ public partial class AssistantService : BaseService
33
34
private const string serviceId = "assistant" ;
34
35
private const string defaultUrl = "https://gateway.watsonplatform.net/assistant/api" ;
35
36
36
- #region Credentials
37
+ #region Authenticator
37
38
/// <summary>
38
- /// Gets and sets the credentials of the service. Replace the default endpoint if endpoint is defined.
39
+ /// Gets and sets the authenticator of the service. Replace the default endpoint if endpoint is defined.
39
40
/// </summary>
40
- public Credentials Credentials
41
+ public Authenticator Authenticator
41
42
{
42
- get { return credentials ; }
43
+ get { return authenticator ; }
43
44
set
44
45
{
45
- credentials = value ;
46
- if ( ! string . IsNullOrEmpty ( credentials . Url ) )
47
- {
48
- Url = credentials . Url ;
49
- }
46
+ authenticator = value ;
50
47
}
51
48
}
52
49
#endregion
@@ -90,17 +87,14 @@ public bool DisableSslVerification
90
87
/// AssistantService constructor.
91
88
/// </summary>
92
89
/// <param name="versionDate">The service version date in `yyyy-mm-dd` format.</param>
93
- public AssistantService ( string versionDate ) : base ( versionDate , serviceId )
94
- {
95
- VersionDate = versionDate ;
96
- }
90
+ public AssistantService ( string versionDate ) : this ( versionDate , ConfigBasedAuthenticatorFactory . GetAuthenticator ( serviceId ) ) { }
97
91
98
92
/// <summary>
99
93
/// AssistantService constructor.
100
94
/// </summary>
101
95
/// <param name="versionDate">The service version date in `yyyy-mm-dd` format.</param>
102
- /// <param name="credentials ">The service credentials .</param>
103
- public AssistantService ( string versionDate , Credentials credentials ) : base ( versionDate , credentials , serviceId )
96
+ /// <param name="authenticator ">The service authenticator .</param>
97
+ public AssistantService ( string versionDate , Authenticator authenticator ) : base ( versionDate , authenticator , serviceId )
104
98
{
105
99
if ( string . IsNullOrEmpty ( versionDate ) )
106
100
{
@@ -111,18 +105,19 @@ public AssistantService(string versionDate, Credentials credentials) : base(vers
111
105
VersionDate = versionDate ;
112
106
}
113
107
114
- if ( credentials . HasCredentials ( ) || credentials . HasTokenData ( ) )
108
+ if ( authenticator != null )
115
109
{
116
- Credentials = credentials ;
110
+ Authenticator = authenticator ;
117
111
118
- if ( string . IsNullOrEmpty ( credentials . Url ) )
112
+ if ( string . IsNullOrEmpty ( Url ) )
119
113
{
120
- credentials . Url = defaultUrl ;
114
+ Authenticator . Url = defaultUrl ;
121
115
}
116
+ Authenticator . Url = Url ;
122
117
}
123
118
else
124
119
{
125
- throw new IBMException ( "Please provide a username and password or authorization token to use the Assistant service. For more information, see https://github.com/watson-developer-cloud/unity-sdk/#configuring-your-service-credentials " ) ;
120
+ throw new IBMException ( "Please provide a username and password or authorization token to use the Assistant service. For more information, see https://github.com/watson-developer-cloud/unity-sdk/#configuring-your-service-authenticator " ) ;
126
121
}
127
122
}
128
123
@@ -170,11 +165,12 @@ public bool CreateSession(Callback<SessionResponse> callback, string assistantId
170
165
171
166
req . OnResponse = OnCreateSessionResponse ;
172
167
173
- RESTConnector connector = RESTConnector . GetConnector ( Credentials , string . Format ( "/v2/assistants/{0}/sessions" , assistantId ) ) ;
168
+ RESTConnector connector = RESTConnector . GetConnector ( Authenticator , string . Format ( "/v2/assistants/{0}/sessions" , assistantId ) ) ;
174
169
if ( connector == null )
175
170
{
176
171
return false ;
177
172
}
173
+ Authenticator . Authenticate ( connector ) ;
178
174
179
175
return connector . Send ( req ) ;
180
176
}
@@ -249,11 +245,12 @@ public bool DeleteSession(Callback<object> callback, string assistantId, string
249
245
250
246
req . OnResponse = OnDeleteSessionResponse ;
251
247
252
- RESTConnector connector = RESTConnector . GetConnector ( Credentials , string . Format ( "/v2/assistants/{0}/sessions/{1}" , assistantId , sessionId ) ) ;
248
+ RESTConnector connector = RESTConnector . GetConnector ( Authenticator , string . Format ( "/v2/assistants/{0}/sessions/{1}" , assistantId , sessionId ) ) ;
253
249
if ( connector == null )
254
250
{
255
251
return false ;
256
252
}
253
+ Authenticator . Authenticate ( connector ) ;
257
254
258
255
return connector . Send ( req ) ;
259
256
}
@@ -343,11 +340,12 @@ public bool Message(Callback<MessageResponse> callback, string assistantId, stri
343
340
344
341
req . OnResponse = OnMessageResponse ;
345
342
346
- RESTConnector connector = RESTConnector . GetConnector ( Credentials , string . Format ( "/v2/assistants/{0}/sessions/{1}/message" , assistantId , sessionId ) ) ;
343
+ RESTConnector connector = RESTConnector . GetConnector ( Authenticator , string . Format ( "/v2/assistants/{0}/sessions/{1}/message" , assistantId , sessionId ) ) ;
347
344
if ( connector == null )
348
345
{
349
346
return false ;
350
347
}
348
+ Authenticator . Authenticate ( connector ) ;
351
349
352
350
return connector . Send ( req ) ;
353
351
}
0 commit comments