// Arrange
 static void Configure(AppleAuthenticationOptions options)
 {
     options.ClientId = "my-client-id";
     options.ClientSecretExpiresAfter = TimeSpan.FromMinutes(1);
     options.KeyId      = "my-key-id";
     options.TeamId     = "my-team-id";
     options.PrivateKey = (_, cancellationToken) => TestKeys.GetPrivateKeyAsync(cancellationToken);
 }
예제 #2
0
    private static string CreateCacheKey(AppleAuthenticationOptions options)
    {
        var segments = new[]
        {
            nameof(DefaultAppleClientSecretGenerator),
            "ClientSecret",
            options.TeamId,
            options.ClientId,
            options.KeyId
        };

        return(string.Join('+', segments));
    }
예제 #3
0
    public static void Validate_Throws_If_KeyId_Is_Null_With_Secret_Generation()
    {
        // Arrange
        var options = new AppleAuthenticationOptions()
        {
            ClientId             = "my-client-id",
            GenerateClientSecret = true,
            KeyId = null,
        };

        // Act and Assert
        Assert.Throws <ArgumentException>("KeyId", () => options.Validate());
    }
예제 #4
0
    public static void Validate_Throws_If_CallbackPath_Is_Null()
    {
        // Arrange
        var options = new AppleAuthenticationOptions()
        {
            ClientId             = "my-client-id",
            GenerateClientSecret = true,
            CallbackPath         = null,
        };

        // Act and Assert
        Assert.Throws <ArgumentException>("CallbackPath", () => options.Validate());
    }
예제 #5
0
    public static void Validate_Throws_If_ClientSecretExpiresAfter_Is_Zero_With_Secret_Generation()
    {
        // Arrange
        var options = new AppleAuthenticationOptions()
        {
            ClientId             = "my-client-id",
            GenerateClientSecret = true,
            KeyId  = "my-key-id",
            TeamId = "my-team-id",
            ClientSecretExpiresAfter = TimeSpan.Zero,
        };

        // Act and Assert
        Assert.Throws <ArgumentOutOfRangeException>("ClientSecretExpiresAfter", () => options.Validate());
    }
예제 #6
0
    /// <summary>
    /// Configures the application to use a specified private to generate a client secret for the provider.
    /// </summary>
    /// <param name="options">The Apple authentication options to configure.</param>
    /// <param name="privateKeyFile">
    /// A delegate to a method to return the <see cref="IFileInfo"/> for the private
    /// key which is passed the value of <see cref="AppleAuthenticationOptions.KeyId"/>.
    /// </param>
    /// <returns>
    /// The value of the <paramref name="options"/> argument.
    /// </returns>
    public static AppleAuthenticationOptions UsePrivateKey(
        [NotNull] this AppleAuthenticationOptions options,
        [NotNull] Func <string, IFileInfo> privateKeyFile)
    {
        options.GenerateClientSecret = true;
        options.PrivateKey           = async(keyId, _) =>
        {
            var fileInfo = privateKeyFile(keyId);

            using var stream = fileInfo.CreateReadStream();
            using var reader = new StreamReader(stream);

            return((await reader.ReadToEndAsync()).AsMemory());
        };

        return(options);
    }
        /// <summary>
        /// Configures the application to use a specified private to generate a client secret for the provider.
        /// </summary>
        /// <param name="options">The Apple authentication options to configure.</param>
        /// <param name="privateKeyFile">
        /// A delegate to a method to return the <see cref="IFileInfo"/> for the private
        /// key which is passed the value of <see cref="AppleAuthenticationOptions.KeyId"/>.
        /// </param>
        /// <returns>
        /// The value of the <paramref name="options"/> argument.
        /// </returns>
        public static AppleAuthenticationOptions UsePrivateKey(
            [NotNull] this AppleAuthenticationOptions options,
            [NotNull] Func <string, IFileInfo> privateKeyFile)
        {
            options.GenerateClientSecret = true;
            options.PrivateKeyBytes      = async(keyId) =>
            {
                var fileInfo = privateKeyFile(keyId);

                using var stream = fileInfo.CreateReadStream();
                using var reader = new StreamReader(stream);

                string privateKey = await reader.ReadToEndAsync();

                if (privateKey.StartsWith("-----BEGIN PRIVATE KEY-----", StringComparison.Ordinal))
                {
                    string[] lines = privateKey.Split('\n');
                    privateKey = string.Join(string.Empty, lines[1..^ 1]);
                }
예제 #8
0
 internal AppleEmailClaimAction(AppleAuthenticationOptions options)
     : base(ClaimTypes.Email, ClaimValueTypes.String)
 {
     _options = options;
 }