public async Task <ResponseWrapper <IdentityResult> > ChangePass([FromBody] ChangePassRequestDTO req) { ClaimsHolder claimsHolder; try { claimsHolder = ClaimsUtils.ValidateUserClaimForIdSrvCall(User); } catch (RestReturnException ex) { return(new ResponseWrapper <IdentityResult>(ex.Value)); } var response = ClientUtils.GetROClient(Constants.A2BB_IDSRV_RESOURCE_NAME, Constants.A2BB_IDSRV_RO_CLIENT_ID, claimsHolder.Name, req.OldPassword); if (response.IsError) { return(new ResponseWrapper <IdentityResult>(Constants.RestReturn.ERR_INVALID_PASS)); } var userClient = new HttpClient(); userClient.DefaultRequestHeaders.Accept.Clear(); userClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); userClient.SetBearerToken(response.AccessToken); var body = new StringContent(JsonConvert.SerializeObject(req), Encoding.UTF8, "application/json"); var res = await userClient.PutAsync(Constants.IDENTITY_SERVER_ENDPOINT + "/api/me/changepass", body); if (!res.IsSuccessStatusCode) { return(new ResponseWrapper <IdentityResult>(Constants.RestReturn.ERR_USER_UPDATE)); } string resContent = await res.Content.ReadAsStringAsync(); var identityRes = JsonConvert.DeserializeObject <ResponseWrapper <IdentityResult> >(resContent); // Fix JSON deserialization if (identityRes.Payload.Errors.GetEnumerator().MoveNext() == false) { var prop = identityRes.Payload.GetType().GetProperty("Succeeded"); prop.SetValue(identityRes.Payload, true); } return(identityRes); }
public ResponseWrapper <string> StartLink([FromBody] NewLinkRequestDTO req) { ClaimsHolder claimsHolder; try { claimsHolder = ClaimsUtils.ValidateUserClaimForIdSrvCall(User); } catch (RestReturnException ex) { return(new ResponseWrapper <string>(ex.Value)); } var sub = _dbContext.Subject.FirstOrDefault(s => s.Id == claimsHolder.Sub); if (sub == null) { sub = new Subject { Id = claimsHolder.Sub }; _dbContext.Subject.Add(sub); _dbContext.SaveChanges(); } var linkHolder = new LinkHolder { Device = req.Device, Username = claimsHolder.Name, Password = req.Password, Subject = claimsHolder.Sub, IsEstabilished = false }; var guid = Guid.NewGuid(); _memCache.Set(guid.ToString(), linkHolder, new MemoryCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(90) }); return(new ResponseWrapper <string>(guid.ToString(), Constants.RestReturn.OK)); }