コード例 #1
0
        /// <summary>
        /// Initializes a new <see cref="SpaceOptions"/>.
        /// </summary>
        public SpaceOptions()
        {
            CallbackPath = new PathString("/signin-space");

            AuthorizationEndpoint   = SpaceDefaults.AuthorizationEndpointPath;
            TokenEndpoint           = SpaceDefaults.TokenEndpointPath;
            UserInformationEndpoint = SpaceDefaults.UserInformationEndpointPath;

            ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "id");
            ClaimActions.MapJsonKey(SpaceClaimTypes.UserId, "id");
            ClaimActions.MapJsonKey(SpaceClaimTypes.UserName, "username");
            ClaimActions.MapCustomJson(SpaceClaimTypes.SmallAvatar, element => element.TryGetProperty("smallAvatar", out var p) && ServerUrl != null ? ServerUrl.ToString().TrimEnd('/') + "/d/" + p.GetString() : null);
            ClaimActions.MapCustomJson(SpaceClaimTypes.ProfilePicture, element => element.TryGetProperty("profilePicture", out var p) && ServerUrl != null ? ServerUrl.ToString().TrimEnd('/') + "/d/" + p.GetString() : null);
            ClaimActions.MapJsonSubKey(SpaceClaimTypes.FirstName, "name", "firstName");
            ClaimActions.MapJsonSubKey(SpaceClaimTypes.LastName, "name", "lastName");
            ClaimActions.MapCustomJson(ClaimTypes.Name, element =>
            {
                if (element.TryGetProperty("name", out var nameElement) && nameElement.ValueKind == JsonValueKind.Object)
                {
                    return(nameElement.TryGetProperty("firstName", out var firstName) &&
                           nameElement.TryGetProperty("lastName", out var lastName)
                        ? $"{firstName} {lastName}"
                        : null);
                }

                return(null);
            });
            ClaimActions.MapCustomJson(ClaimTypes.Email, element =>
            {
                if (element.TryGetProperty("emails", out var emailElements) && emailElements.ValueKind == JsonValueKind.Array)
                {
                    var emailElement = emailElements.EnumerateArray().FirstOrDefault();
                    if (emailElement.TryGetProperty("email", out var email))
                    {
                        return(email.GetString());
                    }
                }

                return(null);
            });
        }
コード例 #2
0
 public void Validate()
 {
     CanTest = ServerUrl != null && !String.IsNullOrEmpty(ServerUrl.ToString());
     IsValid = ServerUrl != null && !String.IsNullOrEmpty(ServerUrl.ToString()) && PollingInterval > 0 && BalloonTimeout > 0;
 }