Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cffa395
Basic Apple provider
martincostello Jun 6, 2019
5c3d7cd
Implement Apple provider
martincostello Jun 8, 2019
f78fa43
Enable Sign In with Apple
martincostello Jun 8, 2019
7ba0afb
Update tests
martincostello Jun 8, 2019
7a24782
Enable token lifetime validation
martincostello Jun 8, 2019
c0fc31c
Add null annotations
martincostello Jun 9, 2019
cd8ed33
Improve exception handling
martincostello Jun 9, 2019
9bc3817
Extend integration tests
martincostello Jun 9, 2019
404730e
Move expiry period to options
martincostello Jun 9, 2019
8b11fe7
Add ClientSecretExpiresAfter validation
martincostello Jun 9, 2019
c7b2f74
Add tests for options validation
martincostello Jun 9, 2019
05a8102
Add unit tests for client secret
martincostello Jun 9, 2019
9948d08
Make KeyId required
martincostello Jun 9, 2019
5e72f38
Fix test
martincostello Jun 9, 2019
2d4794a
Fix Linux and macOS secret generation
martincostello Jun 9, 2019
13012dd
Add password option for pfx files
martincostello Jun 9, 2019
b9f329a
Fix flaky test
martincostello Jun 9, 2019
210fbf9
Add UsePrivateKey() method
martincostello Jun 9, 2019
94f1737
Bump System.IdentityModel.Tokens.Jwt
martincostello Jun 9, 2019
67dc9a3
Set response_mode to form_post
martincostello Sep 8, 2019
eae3d43
Use latest C# version
martincostello Sep 8, 2019
4a93eb6
Retrieve user details after sign-in
martincostello Sep 8, 2019
74f607a
Update branding
martincostello Sep 15, 2019
dbbf2db
Access events via options
martincostello Sep 15, 2019
785a01a
Resolve logging TODO
martincostello Sep 15, 2019
eb5ccfd
Comment out Apple option
martincostello Sep 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add UsePrivateKey() method
Add UsePrivateKey() extension method that configures a private key file to use to auto-generate client secrets.
  • Loading branch information
martincostello committed Sep 8, 2019
commit 210fbf9ec2faab43bad1f0a281b8572fc0b41825
26 changes: 2 additions & 24 deletions samples/Mvc.Client/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* for more information concerning the license and the contributors participating to this project.
*/

using System;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -44,30 +41,11 @@ public void ConfigureServices(IServiceCollection services)

.AddApple(options =>
{
options.GenerateClientSecret = true;
options.ClientId = Configuration["AppleClientId"];
options.KeyId = Configuration["AppleKeyId"];
options.TeamId = Configuration["AppleTeamId"];

options.PrivateKeyBytes = async (keyId) =>
{
var privateKeyFile = HostingEnvironment.ContentRootFileProvider.GetFileInfo($"AuthKey_{keyId}.p8");
string privateKey;

using (var stream = privateKeyFile.CreateReadStream())
using (var reader = new StreamReader(stream))
{
privateKey = await reader.ReadToEndAsync();
}

if (privateKey.StartsWith("-----BEGIN PRIVATE KEY-----", StringComparison.Ordinal))
{
string[] keyLines = privateKey.Split('\n');
privateKey = string.Join(string.Empty, keyLines.Skip(1).Take(keyLines.Length - 2));
}

return Convert.FromBase64String(privateKey);
};
options.UsePrivateKey(
(keyId) => HostingEnvironment.ContentRootFileProvider.GetFileInfo($"AuthKey_{keyId}.p8"));
})

.AddGoogle(options =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
* for more information concerning the license and the contributors participating to this project.
*/

using System;
using System.IO;
using System.Linq;
using AspNet.Security.OAuth.Apple;
using JetBrains.Annotations;
using Microsoft.Extensions.FileProviders;

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods to configure Sign In with Apple authentication capabilities for an HTTP application pipeline.
/// </summary>
public static class AppleAuthenticationOptionsExtensions
{
/// <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>
/// <param name="privateKeyPassword">The optional password for the private key.</param>
/// <returns>
/// The value of the <paramref name="options"/> argument.
/// </returns>
public static AppleAuthenticationOptions UsePrivateKey(
[NotNull] this AppleAuthenticationOptions options,
[NotNull] Func<string, IFileInfo> privateKeyFile,
[CanBeNull] string privateKeyPassword = null)
{
options.GenerateClientSecret = true;
options.PrivateKeyPassword = privateKeyPassword ?? string.Empty;
options.PrivateKeyBytes = async (keyId) =>
{
var fileInfo = privateKeyFile(keyId);
string privateKey;

using (var stream = fileInfo.CreateReadStream())
using (var reader = new StreamReader(stream))
{
privateKey = await reader.ReadToEndAsync();
}

if (privateKey.StartsWith("-----BEGIN PRIVATE KEY-----", StringComparison.Ordinal))
{
string[] lines = privateKey.Split('\n');
privateKey = string.Join(string.Empty, lines.Skip(1).Take(lines.Length - 2));
}

return Convert.FromBase64String(privateKey);
};

return options;
}
}
}