public static WorkflowIdentity Parse(string identity, bool throwOnError) { if (HasControlCharacter(identity)) { if (throwOnError) { throw CoreWf.Internals.FxTrace.Exception.Argument(paramName, SR.IdentityControlCharacter); } return(null); } IdentityParser parser = new IdentityParser(); parser._throwOnError = throwOnError; parser._match = s_identityString.Match(identity.Trim()); if (parser._match.Success) { return(parser.Parse()); } else if (throwOnError) { throw CoreWf.Internals.FxTrace.Exception.Argument(paramName, SR.BadWorkflowIdentityFormat); } else { return(null); } }
public static WorkflowIdentity Parse(string identity, bool throwOnError) { if (HasControlCharacter(identity)) { if (throwOnError) { throw FxTrace.Exception.Argument(paramName, SR.IdentityControlCharacter); } return(null); } var parser = new IdentityParser { throwOnError = throwOnError, match = identityString.Match(identity.Trim()) }; if (parser.match.Success) { return(parser.Parse()); } else if (throwOnError) { throw FxTrace.Exception.Argument(paramName, SR.BadWorkflowIdentityFormat); } else { return(null); } }
public void Parse_ClaimsPrincipal_ReturnsApplicationUser( IdentityParser sut, Mock <ClaimsPrincipal> mockClaimsPrincipal, string subject, string lastName, string name ) { //Arrange mockClaimsPrincipal.Setup(_ => _.Claims) .Returns(new List <Claim> { new Claim("sub", subject), new Claim("last_name", lastName), new Claim("name", name) }); //Act var viewModel = sut.Parse(mockClaimsPrincipal.Object); //Assert viewModel.Id.Should().Be(subject); viewModel.LastName.Should().Be(lastName); viewModel.Name.Should().Be(name); }
public static WorkflowIdentity Parse(string identity) { if (identity == null) { throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("identity"); } return(IdentityParser.Parse(identity, true)); }
public static WorkflowIdentity Parse(string identity) { if (identity == null) { throw FxTrace.Exception.ArgumentNull(nameof(identity)); } return(IdentityParser.Parse(identity, true)); }
public static bool TryParse(string identity, out WorkflowIdentity result) { if (identity == null) { result = null; return(false); } result = IdentityParser.Parse(identity, false); return(result != null); }
public void Parse_NoClaimsPrincipal_ThrowArgumentException( IdentityParser sut, Mock <IPrincipal> mockPrincipal ) { //Arrange //Act Action act = () => sut.Parse(mockPrincipal.Object); //Assert act.Should().Throw <ArgumentException>(); }
public static async Task <bool> LoginIdsAsync() { var browser = DependencyService.Get <IBrowser>(); var options = new OidcClientOptions { Authority = Constants.AuthServerUrl, ClientId = "kinaunaxamarin2", RedirectUri = "kinaunaxamarinclients://callback", PostLogoutRedirectUri = "kinaunaxamarinclients://callback", Scope = "openid profile email firstname middlename lastname timezone viewchild kinaunaprogenyapi kinaunamediaapi", Browser = browser, ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect }; var oidcClient = new OidcClient(options); var result = await oidcClient.LoginAsync(new LoginRequest()); if (result.IsError) { Debug.WriteLine(result.Error); return(false); } else { ApplicationUser user = IdentityParser.Parse(result.User); try { TimeZoneInfo.FindSystemTimeZoneById(user.TimeZone); } catch (Exception) { user.TimeZone = TZConvert.WindowsToIana(user.TimeZone); } try { await SecureStorage.SetAsync(Constants.AuthAccessTokenKey, result.AccessToken); await SecureStorage.SetAsync(Constants.AuthAccessTokenExpiresKey, result.AccessTokenExpiration.Ticks.ToString()); await SecureStorage.SetAsync(Constants.AuthIdTokenKey, result.IdentityToken); await SecureStorage.SetAsync(Constants.UserNameKey, user.UserName); await SecureStorage.SetAsync(Constants.UserEmailKey, user.Email); await SecureStorage.SetAsync(Constants.UserFirstNameKey, user.FirstName); await SecureStorage.SetAsync(Constants.UserMiddleNameKey, user.MiddleName); await SecureStorage.SetAsync(Constants.UserLastNameKey, user.LastName); await SecureStorage.SetAsync(Constants.UserIdKey, user.Id); if (user.ViewChild == 0) { List <Progeny> progenyList = await ProgenyService.GetProgenyList(user.Email); if (progenyList.Any()) { user.ViewChild = progenyList.First().Id; } else { user.ViewChild = Constants.DefaultChildId; } } await SecureStorage.SetAsync(Constants.UserViewChildKey, user.ViewChild.ToString()); await ProgenyService.GetProgeny(user.ViewChild); await UserService.GetUserInfo(user.Email); await SecureStorage.SetAsync(Constants.UserTimezoneKey, user.TimeZone); await RegisterDevice(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } return(true); }
public void Parse_returns_null_when_value_cannot_be_converted(IdentityParser sut) { Assert.That(sut.Parse(typeof(Cat), "Nope"), Is.Null); }
public void Parse_gets_identity_when_value_can_be_converted(IdentityParser sut) { Assert.That(sut.Parse(typeof(Cat), "55"), Is.EqualTo(new Identity <int, Cat>(55))); }