public void NotRequiredClaimsValueWithValuesShouldSerializeToJson() { var claims = ClaimsValue.WithValues(false, "1263746", "23456712"); var expected = "{\"values\":[\"1263746\",\"23456712\"]}"; var serialized = JsonConvert.SerializeObject(claims); Assert.AreEqual(expected, serialized); }
public void NotRequiredClaimsValueWithValueShouldSerializeToJson() { var claims = ClaimsValue.WithValue(false, "1263746"); var expected = "{\"value\":\"1263746\"}"; var serialized = JsonConvert.SerializeObject(claims); Assert.AreEqual(expected, serialized); }
public void RequiredClaimsValueShouldSerializeToJson() { var claims = ClaimsValue.Required(); var expected = "{\"essential\":true}"; var serialized = JsonConvert.SerializeObject(claims); Assert.AreEqual(expected, serialized); }
public void UserInfoShouldSet() { var claims = new ClaimsDictionary { ["test"] = ClaimsValue.Required(), ["test2"] = ClaimsValue.WithValue(false, "1000"), }; var parameter = new ClaimsParameter(); parameter.UserInfo = claims; Assert.AreEqual(claims, parameter.UserInfo); }
public async Task <string> Login(IFireBaseLoginModel model) { FirebaseToken decodedToken = await FirebaseAuth.DefaultInstance .VerifyIdTokenAsync(model.IdToken); string uid = decodedToken.Uid; if (!decodedToken.Claims.TryGetValue("firebase", out var claimsobj)) { throw new InvalidOperationException("No such claim with key 'firebase'"); } if (claimsobj == null) { throw new InvalidOperationException("No such claim with key 'firebase'"); } var claims = claimsobj.ToString(); ClaimsValue value = null; try { value = JsonConvert.DeserializeObject <ClaimsValue>(claims); } catch (Exception e) { throw; } var platformId = ""; switch (value.Sign_in_provider) { case "apple.com": { if (value.Identities.TryGetValue("apple.com", out var ids)) { if (ids != null && ids.Any()) { platformId = ids.First(); } } break; } case "facebook.com": { if (value.Identities.TryGetValue("facebook.com", out var ids)) { if (ids != null && ids.Any()) { platformId = ids.First(); } } break; } case "google.com": { if (value.Identities.TryGetValue("google.com", out var ids)) { if (ids != null && ids.Any()) { platformId = ids.First(); } } break; } default: throw new ArgumentOutOfRangeException(); } var userName = string.IsNullOrWhiteSpace(model.DataModel.UserName) ? $"{value.Sign_in_provider}_User_{Guid.NewGuid()}" : model.DataModel.UserName; if (string.IsNullOrWhiteSpace(platformId)) { throw new InvalidOperationException("PlatformId is empty"); } var fireBaseId = uid; return (await _userService.GetOrAddFireBaseUser(userName, fireBaseId, value.Sign_in_provider, platformId)); }