|
1 | 1 | using System; |
2 | 2 | using System.Collections.Generic; |
3 | 3 | using System.Linq; |
| 4 | +using System.Reflection; |
4 | 5 | using Newtonsoft.Json; |
5 | 6 | using Newtonsoft.Json.Linq; |
6 | 7 | using SimpleRestServices.Client; |
@@ -215,18 +216,27 @@ public User GetUser(CloudIdentity identity, string userId) |
215 | 216 | return response.Data.User; |
216 | 217 | } |
217 | 218 |
|
218 | | - public User AddUser(CloudIdentity identity, User user) |
| 219 | + public NewUser AddUser(CloudIdentity identity, NewUser newUser) |
219 | 220 | { |
220 | | - var response = ExecuteRESTRequest<UserResponse>(identity, "/v2.0/users", HttpMethod.POST, new AddUserRequest { User = user }); |
| 221 | + newUser.Id = null; |
| 222 | + |
| 223 | + var response = ExecuteRESTRequest<NewUserResponse>(identity, "/v2.0/users", HttpMethod.POST, new AddUserRequest { User = newUser }); |
221 | 224 |
|
222 | 225 | if (response == null || response.Data == null) |
223 | 226 | return null; |
224 | 227 |
|
225 | | - return response.Data.User; |
| 228 | + // If the user specifies a password, then the password will not be in the response, so we need to fill it in on the return object. |
| 229 | + if (string.IsNullOrWhiteSpace(response.Data.NewUser.Password)) |
| 230 | + response.Data.NewUser.Password = newUser.Password; |
| 231 | + |
| 232 | + return response.Data.NewUser; |
226 | 233 | } |
227 | 234 |
|
228 | 235 | public User UpdateUser(CloudIdentity identity, User user) |
229 | 236 | { |
| 237 | + if(user == null || string.IsNullOrWhiteSpace(user.Id)) |
| 238 | + throw new ArgumentException("The User or User.Id values cannot be null."); |
| 239 | + |
230 | 240 | var urlPath = string.Format("v2.0/users/{0}", user.Id); |
231 | 241 |
|
232 | 242 | var updateUserRequest = new UpdateUserRequest { User = user }; |
@@ -378,7 +388,7 @@ protected virtual Response ExecuteRESTRequest(CloudIdentity identity, string url |
378 | 388 | bodyStr = JsonConvert.SerializeObject(body, new JsonSerializerSettings{NullValueHandling = NullValueHandling.Ignore}); |
379 | 389 | } |
380 | 390 |
|
381 | | - var response = _restService.Execute<T>(url, method, bodyStr, headers, queryStringParameter, new JsonRequestSettings() { RetryCount = retryCount, RetryDelayInMS = retryDelay, Non200SuccessCodes = new[] { 401, 409 } }); |
| 391 | + var response = _restService.Execute<T>(url, method, bodyStr, headers, queryStringParameter, new JsonRequestSettings() { RetryCount = retryCount, RetryDelayInMS = retryDelay, Non200SuccessCodes = new[] { 401, 409 }, UserAgent = ProviderBase.GetUserAgentHeaderValue()}); |
382 | 392 |
|
383 | 393 | // on errors try again 1 time. |
384 | 394 | if (response.StatusCode == 401 && !isRetry && !isTokenRequest) |
|
0 commit comments