Skip to content

Commit 1efae53

Browse files
committed
refactor: add check for url
1 parent 4f468e6 commit 1efae53

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

Authentication/Iam/IamAuthenticator.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ public IamAuthenticator(Dictionary<string, string> config)
7373
config.TryGetValue(PropNameClientSecret, out string clientSecret);
7474
config.TryGetValue(PropNameDisableSslVerification, out string disableSslVerficiationString);
7575
bool.TryParse(disableSslVerficiationString, out bool disableSslVerification);
76-
Log.Debug("IamAuthenticator:{0} {1} {2} {3}", apikey);
7776
Init(apikey, url, clientId, clientSecret, disableSslVerification);
7877
}
7978

@@ -168,19 +167,6 @@ bool RequestToken(Callback<IamTokenResponse> callback)
168167
if (callback == null)
169168
throw new ArgumentNullException("successCallback");
170169

171-
// Use bx:bx as default auth header creds.
172-
var clientId = "bx";
173-
var clientSecret = "bx";
174-
175-
// If both the clientId and secret were specified by the user, then use them.
176-
if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(ClientSecret))
177-
{
178-
Log.Debug("not null: {0}", ClientId);
179-
180-
clientId = ClientId;
181-
clientSecret = ClientSecret;
182-
}
183-
184170
RESTConnector connector = new RESTConnector();
185171
connector.URL = Url;
186172
if (connector == null)
@@ -190,7 +176,11 @@ bool RequestToken(Callback<IamTokenResponse> callback)
190176
req.Callback = callback;
191177
req.HttpMethod = UnityWebRequest.kHttpVerbGET;
192178
req.Headers.Add("Content-type", "application/x-www-form-urlencoded");
193-
req.Headers.Add("Authorization", Utility.CreateAuthorization(clientId, clientSecret));
179+
// If both the clientId and secret were specified by the user, then use them.
180+
if (!string.IsNullOrEmpty(ClientId) && !string.IsNullOrEmpty(ClientSecret))
181+
{
182+
req.Headers.Add("Authorization", Utility.CreateAuthorization(ClientId, ClientSecret));
183+
}
194184
req.OnResponse = OnRequestIamTokenResponse;
195185
req.DisableSslVerification = DisableSslVerification;
196186
req.Forms = new Dictionary<string, RESTConnector.Form>();
@@ -250,9 +240,9 @@ public override void Validate()
250240
throw new ArgumentException(string.Format(ErrorMessagePropInvalid, "url"));
251241
}
252242

253-
if (string.IsNullOrEmpty(ClientSecret) || string.IsNullOrEmpty(ClientId))
243+
if (!string.IsNullOrEmpty(ClientSecret) && string.IsNullOrEmpty(ClientId) || string.IsNullOrEmpty(ClientSecret) && !string.IsNullOrEmpty(ClientId))
254244
{
255-
Log.Warning("IamTokenManager():", "Warning: Client ID and Secret must BOTH be given, or the defaults will be used.");
245+
Log.Warning("IamAuthenticator():", "Warning: Client ID and Secret must BOTH be provided.");
256246
}
257247
}
258248
}

Connection/RESTConnector.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ public bool? DisableSslVerification
264264
///
265265
public static RESTConnector GetConnector(Authenticator authenticator, string function, string url)
266266
{
267+
if (string.IsNullOrEmpty(url))
268+
{
269+
throw new ArgumentNullException("The Url must not be empty or null.");
270+
}
271+
267272
if (Utility.HasBadFirstOrLastCharacter(url))
268273
{
269274
throw new ArgumentException("The Url property is invalid. Please remove any surrounding {{, }}, or \" characters.");

Connection/WSConnector.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ public static string FixupURL(string URL)
330330
/// <returns>The WSConnector object or null or error.</returns>
331331
public static WSConnector CreateConnector(Authenticator authenticator, string function, string args, string url)
332332
{
333+
if (string.IsNullOrEmpty(url))
334+
{
335+
throw new ArgumentNullException("The Url must not be empty or null.");
336+
}
337+
333338
if (Utility.HasBadFirstOrLastCharacter(url))
334339
{
335340
throw new ArgumentException("The Url property is invalid. Please remove any surrounding {{, }}, or \" characters.");

0 commit comments

Comments
 (0)