Skip to content

Commit 700e198

Browse files
committed
feat(ICP): Allow basic auth when authenticating using apikey:icp-<apikey>, use basicauth if authenticating with tokenoptions with an icp-<apikey>
1 parent e67629e commit 700e198

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

Scripts/Utilities/Credentials.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class Credentials
3636
private string _iamApiKey;
3737
private string _userAcessToken;
3838
private const string APIKEY_AS_USERNAME = "apikey";
39+
private const string ICP_PREFIX = "icp-";
3940
#endregion
4041

4142
#region Public Fields
@@ -146,7 +147,7 @@ public Credentials(TokenOptions iamTokenOptions, string serviceUrl = null)
146147
#region SetCredentials
147148
private void SetCredentials(string username, string password, string url = null)
148149
{
149-
if (username == APIKEY_AS_USERNAME)
150+
if (username == APIKEY_AS_USERNAME && !password.StartsWith(ICP_PREFIX))
150151
{
151152
TokenOptions tokenOptions = new TokenOptions()
152153
{
@@ -167,18 +168,25 @@ private void SetCredentials(string username, string password, string url = null)
167168

168169
private void SetCredentials(TokenOptions iamTokenOptions, string serviceUrl = null)
169170
{
170-
if (!string.IsNullOrEmpty(serviceUrl))
171-
Url = serviceUrl;
172-
_iamUrl = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
173-
_iamTokenData = new IamTokenData();
171+
if (iamTokenOptions.IamApiKey.StartsWith(ICP_PREFIX))
172+
{
173+
SetCredentials(APIKEY_AS_USERNAME, iamTokenOptions.IamApiKey, serviceUrl);
174+
}
175+
else
176+
{
177+
if (!string.IsNullOrEmpty(serviceUrl))
178+
Url = serviceUrl;
179+
_iamUrl = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
180+
_iamTokenData = new IamTokenData();
174181

175-
if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
176-
_iamApiKey = iamTokenOptions.IamApiKey;
182+
if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
183+
_iamApiKey = iamTokenOptions.IamApiKey;
177184

178-
if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
179-
this._userAcessToken = iamTokenOptions.IamAccessToken;
185+
if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
186+
this._userAcessToken = iamTokenOptions.IamAccessToken;
180187

181-
GetToken();
188+
GetToken();
189+
}
182190
}
183191
#endregion
184192

0 commit comments

Comments
 (0)