public void testGetIdentity() { XooaClient xooaClient = new XooaClient(); xooaClient.setApiToken(XooaConstants.API_TOKEN); try { IdentityResponse identityResponse = xooaClient.getIdentity("3c7d983f-6f9c-4599-802f-cd07dc977a7d"); Assert.IsNotEmpty(identityResponse.getId()); Assert.IsNotEmpty(identityResponse.getIdentityName()); Assert.IsNotNull(identityResponse.getCanManageIdentities()); Assert.IsNotEmpty(identityResponse.getCreatedAt()); Assert.IsNotEmpty(identityResponse.getAccess()); Assert.IsNotEmpty(identityResponse.getAttrsList()); } catch (XooaRequestTimeoutException xrte) { Assert.IsNotEmpty(xrte.getResultId()); Assert.IsNotEmpty(xrte.getResultUrl()); } }
public async Task <IdentityResponse> CreateUser(UserInRoleDTO <Employee, User, Role> userInRole) { try { var identityResponse = new IdentityResponse(); IdentityUser user = new IdentityUser { UserName = userInRole.User.UserName, // Email = userInRole.User.Email }; var result = await this.userManager.CreateAsync(user, userInRole.User.Password); if (result.Succeeded) { foreach (var role in userInRole.Roles) { this.userManager.AddToRole(user.Id, role.Name); } identityResponse.UserId = user.Id; identityResponse.Succeeded = result.Succeeded; } else { identityResponse.Errors = result.Errors; } return(identityResponse); } catch (Exception) { throw; } }
public void testCurrentIdentity() { XooaClient xooaClient = new XooaClient(); xooaClient.setApiToken(XooaConstants.API_TOKEN); try { IdentityResponse currentIdentity = xooaClient.currentIdentity(); Assert.IsNotEmpty(currentIdentity.getId()); Assert.IsNotEmpty(currentIdentity.getIdentityName()); Assert.IsNotNull(currentIdentity.getCanManageIdentities()); Assert.IsNotEmpty(currentIdentity.getCreatedAt()); Assert.IsNotEmpty(currentIdentity.getAccess()); Assert.IsNotEmpty(currentIdentity.getAttrsList()); } catch (XooaRequestTimeoutException xrte) { Assert.IsNotEmpty(xrte.getResultId()); Assert.IsNotEmpty(xrte.getResultUrl()); } }
public async Task <IHttpActionResult> Register(UserInRoleDTO <Employee, User, Role> userInRole) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } IdentityResponse result = await authRepo.CreateUser(userInRole); if (result.Errors != null) { return(Json(result.Errors)); } var employeeInRole = new EmployeeInRole { EmployeeId = userInRole.Employee.EmployeeId, UserId = result.UserId }; this.employeeInRoleService.AddUpdateEmployeeInRole(employeeInRole); return(Json(HttpStatusCode.OK)); } catch (Exception e) { throw; } }
public void testGetIdentities() { XooaClient xooaClient = new XooaClient(); xooaClient.setApiToken(XooaConstants.API_TOKEN); try { List <IdentityResponse> identities = xooaClient.getIdentities(); IdentityResponse identity = identities[0]; Assert.IsNotEmpty(identities); Assert.IsNotEmpty(identity.getId()); Assert.IsNotEmpty(identity.getIdentityName()); Assert.IsNotNull(identity.getCanManageIdentities()); Assert.IsNotEmpty(identity.getCreatedAt()); } catch (XooaRequestTimeoutException xrte) { Assert.IsNotEmpty(xrte.getResultId()); Assert.IsNotEmpty(xrte.getResultUrl()); } }
public void testEnrollIdentity() { XooaClient xooaClient = new XooaClient(); xooaClient.setApiToken(XooaConstants.API_TOKEN); try { var attrs = new List <attrs>(); attrs.Add(new attrs("sample", "value", false)); IdentityRequest request = new IdentityRequest("Kavi", "r", true, attrs); IdentityResponse identityResponse = xooaClient.enrollIdentity(request); identityResponse.display(); Assert.IsNotEmpty(identityResponse.getId()); Assert.IsNotEmpty(identityResponse.getIdentityName()); Assert.IsNotNull(identityResponse.getCanManageIdentities()); Assert.IsNotEmpty(identityResponse.getCreatedAt()); Assert.IsNotEmpty(identityResponse.getAccess()); Assert.IsNotEmpty(identityResponse.getAttrsList()); } catch (XooaRequestTimeoutException xrte) { Assert.IsNotEmpty(xrte.getResultId()); Assert.IsNotEmpty(xrte.getResultUrl()); } }
public void ConstructorShouldSetResponseWithNullContent() { var response = new RestResponse(System.Net.HttpStatusCode.Accepted, null); var actual = new IdentityResponse(response, IdentityService.InfoType.UserInfo); Assert.IsNull(actual.ResponseJson); }
public async Task <IdentityResponse> HasClaimAsync(ApplicationUser user, Claim claim) { var claims = await _userManager.GetClaimsAsync(user); return(claims.Any(x => x.Type == claim.Type && x.Value == claim.Value) ? IdentityResponse.Success("Claim Exists") : IdentityResponse.Fail("Claim does not exist")); }
public void WriteJson_WhenGivenValidObject_ReturnsProperJson() { var o = new IdentityResponse(new SentinelClaim(ClaimType.Name, "azzlack"), new SentinelClaim(ClaimType.Issuer, "Sentinel.OAuth"), new SentinelClaim(ClaimType.Scope, "read"), new SentinelClaim(ClaimType.Scope, "write")); var json = JsonConvert.SerializeObject(o); Assert.AreEqual("{\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\":\"azzlack\",\"urn:oauth:issuer\":\"Sentinel.OAuth\",\"urn:oauth:scope\":\"read\",\"urn:oauth:scope\":\"write\"}", json); }
public void ConstructorShouldSetResponseJson() { string responseJson = "{\"sub\":\"411421B0-38D6-6568-A53A-DF99691B7EB6\",\"email\":\"[email protected]\",\"email_verified\":true}"; var response = new RestResponse(System.Net.HttpStatusCode.Accepted, responseJson); var actual = new IdentityResponse(response, IdentityService.InfoType.UserInfo); Assert.AreEqual(responseJson, actual.ResponseJson); }
public void ResponseDataAsShouldReturnDefaultIfResponseJsonNull() { var response = new RestResponse(System.Net.HttpStatusCode.Accepted, null); var userInfoResponse = new IdentityResponse(response, IdentityService.InfoType.UserInfo); var actual = userInfoResponse.ResponseDataAs <UserInfoData>(); Assert.IsNull(actual); }
private Mock <IApplicationSignInManager> GetMockApplicationSignInManager() { var applicationSignInManager = new Mock <IApplicationSignInManager>(MockBehavior.Strict); applicationSignInManager.Setup(x => x.PasswordSignInAsync(It.IsAny <ApplicationUser>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); applicationSignInManager.Setup(x => x.SignOutAsync()); return(applicationSignInManager); }
private Mock <IApplicationUserManager> GetMockApplicationUserManager() { var applicationUserManager = new Mock <IApplicationUserManager>(MockBehavior.Strict); applicationUserManager.Setup(x => x.RegisterUserAsync(It.IsAny <ApplicationUser>())) .ReturnsAsync(IdentityResponse.Success("Succeeded")); applicationUserManager.Setup(x => x.GetUserByNameAsync(It.IsAny <string>())) .ReturnsAsync(DefaultApplicationUsers.GetSuperUser()); return(applicationUserManager); }
/// <summary> /// Identifies the image async. Image will be scaled to approximately 400 x 400 pixels to be processed /// </summary> /// <returns>Whether the user was identified or not</returns> /// <param name="imageLargerThan400x400">Image larger than400x400.</param> public async Task <IdentityResponse> IdentifyImageAsync(byte[] imageLargerThan400x400) { var returnValue = new IdentityResponse(); var resizedBytes = DependencyService.Get <IResizer>().ResizeImage(imageLargerThan400x400, 400, 400); var contentObject = ImageUpload.CreateNew(); contentObject.users.Add(new User(Convert.ToBase64String(resizedBytes))); var content = new StringContent(JsonConvert.SerializeObject(contentObject), System.Text.Encoding.UTF8, "application/json"); var result = await client.PostAsync("http://michaels-it-org-facialrecognition.azurewebsites.net/api/identify/v1.0/check", content); var response = await result.Content.ReadAsStringAsync(); response = response.Replace("\"", ""); System.Diagnostics.Debug.WriteLine($"{response}"); if (response.Contains("@")) { returnValue.Response = IdentityType.Success; returnValue.Data = response; return(returnValue); } switch (response) { case "Please take off glasses": returnValue.Response = IdentityType.Glasses; break; case "No face detected": returnValue.Response = IdentityType.NoFacesDetected; break; case "User not found": returnValue.Response = IdentityType.UserNotFound; break; case "Unable to Identify User": returnValue.Response = IdentityType.Failure; break; case "Error": returnValue.Response = IdentityType.Error; break; default: returnValue.Response = IdentityType.Failure; break; } return(returnValue); }
public void ResponseDataAsShouldReuseConvertedResponse() { string responseJson = "{\"sub\":\"411421B0-38D6-6568-A53A-DF99691B7EB6\",\"email\":\"[email protected]\",\"email_verified\":true,\"phone_number\":\"+447700200200\",\"phone_number_verified\":true,\"birthdate\":\"1990-04-11\",\"updated_at\":\"1460779506\",\"address\":{\"formatted\":\"123 Fake Street \r\n Manchester\",\"postal_code\":\"M1 1AB\"}}"; var response = new RestResponse(System.Net.HttpStatusCode.Accepted, responseJson); var userInfoResponse = new IdentityResponse(response, IdentityService.InfoType.UserInfo); var first = userInfoResponse.ResponseDataAs <UserInfoData>(); var second = userInfoResponse.ResponseDataAs <UserInfoData>(); Assert.AreSame(first, second); }
public void ConstructorShouldSetErrorForInvalidFormatResponseDataForPremiumInfo() { string responseJson = "<html>not valid</html>"; var response = new RestResponse(System.Net.HttpStatusCode.Accepted, responseJson); var actual = new IdentityResponse(response, IdentityService.InfoType.PremiumInfo); Assert.IsNotNull(actual.ErrorResponse); Assert.AreEqual("invalid_format", actual.ErrorResponse.Error); Assert.AreEqual("{\"error\":\"invalid_format\",\"error_description\":\"Received PremiumInfo response that is not JSON or JWT format\"}", actual.ResponseJson); }
public async Task <IdentityResponse> RemoveFromRoleAsync(ApplicationUser user, string roleName) { if (roleName == DefaultApplicationRoles.SuperAdmin) { return(IdentityResponse.Fail("Can not to delete superAdmin role")); } var rs = await _userManager.RemoveFromRoleAsync(user, roleName); return(rs.ToIdentityResponse()); }
public void ConstructorShouldSetResponseWithDecodedJWTPayload() { string responseJWT = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0MTE0MjFCMC0zOEQ2LTY1NjgtQTUzQS1ERjk5NjkxQjdFQjYiLCJlbWFpbCI6InRlc3QyQGV4YW1wbGUuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWV9.AcpILNH2Uvok99MQWwxP6X7x3OwtVmTOw0t9Hq00gmQ"; var response = new RestResponse(System.Net.HttpStatusCode.Accepted, responseJWT); var actual = new IdentityResponse(response, IdentityService.InfoType.UserInfo); JObject json = JObject.Parse(actual.ResponseJson); Assert.IsNotNull(actual.ResponseJson); Assert.AreEqual("411421B0-38D6-6568-A53A-DF99691B7EB6", (string)json["sub"]); Assert.AreEqual("*****@*****.**", (string)json["email"]); Assert.AreEqual(true, (bool)json["email_verified"]); }
public void ShowAlert(Action callback, IdentityResponse identityResponse) { FragmentManager fm = ((AppCompatActivity)Forms.Context).SupportFragmentManager; MainActivity.dialog.CallBack = callback; MainActivity.dialog.IdentityVerification = identityResponse.Response; if (!string.IsNullOrEmpty(identityResponse.Data)) { MainActivity.dialog.IdentifiedEmail = identityResponse.Data; } MainActivity.dialog.Show(fm, "Alert"); }
public void ConstructorShouldSetErrorForAuthenticationError() { var response = new RestResponse(System.Net.HttpStatusCode.Unauthorized, ""); response.Headers = new List <BasicKeyValuePair> { new BasicKeyValuePair("WWW-Authenticate", "Bearer error = \"invalid_request\", error_description = \"No Access Token\"") }; var actual = new IdentityResponse(response, IdentityService.InfoType.UserInfo); Assert.IsNotNull(actual.ErrorResponse); Assert.AreEqual("invalid_request", actual.ErrorResponse.Error); Assert.AreEqual("No Access Token", actual.ErrorResponse.ErrorDescription); }
/// <summary> /// Creates a status with ResponseType Identity and the complete <see cref="IdentityResponse"/>. /// Indicates that an identity request has been successful. /// </summary> /// <param name="response">UserInfoResponse returned from <see cref="IIdentityService"/></param> /// <param name="caller">Name of calling method</param> /// <returns>MobileConnectStatus with ResponseType Identity</returns> public static MobileConnectStatus Identity(IdentityResponse response, [CallerMemberName] string caller = null) { if (response.ErrorResponse != null) { return(Error(response.ErrorResponse)); } Log.Info(() => $"MobileConnectStatus Identity returned caller={caller}"); return(new MobileConnectStatus { ResponseType = MobileConnectResponseType.Identity, IdentityResponse = response, }); }
public async Task <IdentityResponse> RegisterUserAsync(ApplicationUser user) { if (user.Email != null && await _userManager.FindByEmailAsync(user.Email) != null) { return(IdentityResponse.Fail("Email already exists! Please try a different one!")); } user.UserName ??= user.Email; if (user.UserName != null && await _userManager.FindByNameAsync(user.UserName) != null) { return(IdentityResponse.Fail("User Name already exists! Please try a different one")); } var rs = await _userManager.CreateAsync(user); return(rs.ToIdentityResponse()); }
public async Task <IdentityResponse> Register(RegisterDto model) { var response = new IdentityResponse(); var user = new IdentityUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); response.UserId = GetUserId(user.UserName); response.Success = result.Succeeded; return(response); }
public async Task <IdentityResponse <bool> > CreateUserAsync(ApplicationUser user, string password) { var response = new IdentityResponse <bool>(false); IdentityResult userCreateResult = await _userManager.CreateAsync(user, password); if (userCreateResult.Succeeded) { response.Result = true; } else { response.AddRangeErrors(userCreateResult.Errors.Select(x => x.Description)); } return(response); }
void buildAlert(IdentityResponse identityResponse) { initializeDialog(); switch (identityResponse.Response) { case IdentityType.Success: title = new NSAttributedString("Success!", foregroundColor: UIColor.FromRGB(82, 158, 63)); message = new NSAttributedString($"Thank you {identityResponse.Data} for verifying yourself. Glad you could make it back!"); break; case IdentityType.Glasses: title = new NSAttributedString("Failure!", foregroundColor: UIColor.Red); message = new NSAttributedString("Unfortunrately we were unable to verify your identity because of your glasses. Please take off your glasses and try again."); break; case IdentityType.UserNotFound: title = new NSAttributedString("Failure!", foregroundColor: UIColor.Red); message = new NSAttributedString("Unfortunrately, this user was not found in our database."); break; case IdentityType.NoFacesDetected: title = new NSAttributedString("No Face Detected!"); message = new NSAttributedString("There were no faces detected in the picture. I'm not crazy and you can't trick me like that. Please take a picture of yourself and I'll verify it again."); break; case IdentityType.Error: title = new NSAttributedString("Error!"); message = new NSAttributedString("KERNAL PANIC - not syncing: Attempted to kill init! exitcode=0x00000100. Restarting.... Whoa that was crazy, something happened. Can you try again?"); break; default: title = new NSAttributedString("Failure!", foregroundColor: UIColor.Red); message = new NSAttributedString("Unfortunrately we were unable to verify your identity. Please try again."); break; } presentDialog(); }
public async Task <IdentityResponse> Login(LoginDto model) { var response = new IdentityResponse(); var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); response.Success = result.Succeeded; if (!result.Succeeded) { return(response); } var user = _userManager.Users.SingleOrDefault(r => r.Email.Equals(model.Email)); response.UserId = user.Id; response.AuthorizationToken = GenerateJwtToken(model.Email, user); return(response); }
public async Task <IdentityResponse <ApplicationUser> > SignInAsync(string login, string password) { var response = new IdentityResponse <ApplicationUser>(null); response.Result = _userManager.Users.SingleOrDefault(u => u.UserName == login); if (response.Result is null) { response.AddError("User not found"); return(response); } var userSigninResult = await _userManager.CheckPasswordAsync(response.Result, password); if (!userSigninResult) { response.AddError("Incorrect password"); } return(response); }
public void ResponseDataAsShouldDeserializeToUserInfoData() { string responseJson = "{\"sub\":\"411421B0-38D6-6568-A53A-DF99691B7EB6\",\"email\":\"[email protected]\",\"email_verified\":true,\"phone_number\":\"+447700200200\",\"phone_number_verified\":true,\"birthdate\":\"1990-04-11\",\"updated_at\":\"1460779506\",\"address\":{\"formatted\":\"123 Fake Street \r\n Manchester\",\"postal_code\":\"M1 1AB\"}}"; var response = new RestResponse(System.Net.HttpStatusCode.Accepted, responseJson); var userInfoResponse = new IdentityResponse(response, IdentityService.InfoType.UserInfo); var actual = userInfoResponse.ResponseDataAs <UserInfoData>(); Assert.IsNotNull(actual); Assert.AreEqual("411421B0-38D6-6568-A53A-DF99691B7EB6", actual.Sub); Assert.AreEqual("*****@*****.**", actual.Email); Assert.AreEqual(true, actual.EmailVerified); Assert.AreEqual("+447700200200", actual.PhoneNumber); Assert.AreEqual(true, actual.PhoneNumberVerified); Assert.IsNotNull(actual.Address); Assert.AreEqual("123 Fake Street \r\n Manchester", actual.Address.Formatted); Assert.AreEqual("M1 1AB", actual.Address.PostalCode); Assert.AreEqual("1990-04-11", actual.Birthdate); Assert.AreEqual(new DateTime(2016, 4, 16, 4, 5, 6), actual.UpdatedAt); }
public async Task <IdentityResponse> PostIdentityTokenAsync(TokenRequest request) { var requestMessage = new HttpRequestMessage { Version = new Version(1, 0), RequestUri = new Uri(string.Concat(IdentityBaseUrl, "/connect/token")), Method = HttpMethod.Post, Content = new FormUrlEncodedContent(request.ToIdentityToken(_platformUtilsService.IdentityClientId)) }; requestMessage.Headers.Add("Accept", "application/json"); request.AlterIdentityTokenHeaders(requestMessage.Headers); HttpResponseMessage response; try { response = await _httpClient.SendAsync(requestMessage); } catch (Exception e) { throw new ApiException(HandleWebError(e)); } JObject responseJObject = null; if (IsJsonResponse(response)) { var responseJsonString = await response.Content.ReadAsStringAsync(); responseJObject = JObject.Parse(responseJsonString); } var identityResponse = new IdentityResponse(response.StatusCode, responseJObject); if (identityResponse.FailedToParse) { throw new ApiException(new ErrorResponse(responseJObject, response.StatusCode, true)); } return(identityResponse); }
public async Task SignOutAsync(string login) { var response = new IdentityResponse <ApplicationUser>(null); await _signInManager.SignOutAsync(); //response.Result = _userManager.Users.SingleOrDefault(u => u.UserName == login); //if (response.Result is null) //{ // response.AddError("User not found"); // return response; //} //var userSigninResult = await _userManager. CheckPasswordAsync(response.Result, password); //if (!userSigninResult) // response.AddError("Incorrect password"); //return response; }