From d1d1d9b9141463d30d60ad67cfd5efcc41d1ca38 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 20 Jan 2021 13:12:10 -0800 Subject: [PATCH 1/3] Add API docs to twitter auth --- ...ft.AspNetCore.Authentication.Twitter.csproj | 1 - .../Twitter/src/TwitterHandler.cs | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj b/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj index f29f858f8aa5..74950e202d30 100644 --- a/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj +++ b/src/Security/Authentication/Twitter/src/Microsoft.AspNetCore.Authentication.Twitter.csproj @@ -3,7 +3,6 @@ ASP.NET Core middleware that enables an application to support Twitter's OAuth 1.0 authentication workflow. $(DefaultNetCoreTargetFramework) - $(NoWarn);CS1591 true aspnetcore;authentication;security diff --git a/src/Security/Authentication/Twitter/src/TwitterHandler.cs b/src/Security/Authentication/Twitter/src/TwitterHandler.cs index d469c147725a..54908f6dfa4c 100644 --- a/src/Security/Authentication/Twitter/src/TwitterHandler.cs +++ b/src/Security/Authentication/Twitter/src/TwitterHandler.cs @@ -22,6 +22,9 @@ namespace Microsoft.AspNetCore.Authentication.Twitter { + /// + /// Authentication handler for Twitter's OAuth based authentication. + /// public class TwitterHandler : RemoteAuthenticationHandler { private static readonly JsonSerializerOptions ErrorSerializerOptions = new JsonSerializerOptions @@ -41,12 +44,18 @@ public class TwitterHandler : RemoteAuthenticationHandler set { base.Events = value; } } + /// + /// Initializes a new instance of . + /// + /// public TwitterHandler(IOptionsMonitor options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock) : base(options, logger, encoder, clock) { } + /// protected override Task CreateEventsAsync() => Task.FromResult(new TwitterEvents()); + /// protected override async Task HandleRemoteAuthenticateAsync() { var query = Request.Query; @@ -130,6 +139,14 @@ protected override async Task HandleRemoteAuthenticateAsync } } + /// + /// Creates an from the specified . + /// + /// The . + /// The . + /// The . + /// The for the user. + /// The . protected virtual async Task CreateTicketAsync( ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token, JsonElement user) { @@ -144,6 +161,7 @@ protected virtual async Task CreateTicketAsync( return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name); } + /// protected override async Task HandleChallengeAsync(AuthenticationProperties properties) { if (string.IsNullOrEmpty(properties.RedirectUri)) From 769de34ffaca6c4b48fc5141bc566c51f9681717 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 20 Jan 2021 13:27:17 -0800 Subject: [PATCH 2/3] Add more docs --- .../Twitter/src/TwitterExtensions.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/Security/Authentication/Twitter/src/TwitterExtensions.cs b/src/Security/Authentication/Twitter/src/TwitterExtensions.cs index 724380569232..e0b64af54a87 100644 --- a/src/Security/Authentication/Twitter/src/TwitterExtensions.cs +++ b/src/Security/Authentication/Twitter/src/TwitterExtensions.cs @@ -9,17 +9,62 @@ namespace Microsoft.Extensions.DependencyInjection { + /// + /// Extension methods to configure Twitter OAuth authentication. + /// public static class TwitterExtensions { + /// + /// Adds Twitter OAuth-based authentication to using the default scheme. + /// The default scheme is specified by . + /// + /// Facebook authentication allows application users to sign in with their Facebook account. + /// + /// + /// The . + /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder) => builder.AddTwitter(TwitterDefaults.AuthenticationScheme, _ => { }); + /// + /// Adds Twitter OAuth-based authentication to using the default scheme. + /// The default scheme is specified by . + /// + /// Facebook authentication allows application users to sign in with their Facebook account. + /// + /// + /// The . + /// A delegate to configure . + /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, Action configureOptions) => builder.AddTwitter(TwitterDefaults.AuthenticationScheme, configureOptions); + /// + /// Adds Twitter OAuth-based authentication to using the default scheme. + /// The default scheme is specified by . + /// + /// Facebook authentication allows application users to sign in with their Facebook account. + /// + /// + /// The . + /// The authentication scheme. + /// A delegate to configure . + /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddTwitter(authenticationScheme, TwitterDefaults.DisplayName, configureOptions); + /// + /// Adds Twitter OAuth-based authentication to using the default scheme. + /// The default scheme is specified by . + /// + /// Facebook authentication allows application users to sign in with their Facebook account. + /// + /// + /// The . + /// The authentication scheme. + /// A display name for the authentication handler. + /// A delegate to configure . + /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) { builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton, TwitterPostConfigureOptions>()); From e1bb48dde4260b1eb47ee9c27962532732b4b685 Mon Sep 17 00:00:00 2001 From: Hao Kung Date: Wed, 20 Jan 2021 13:31:14 -0800 Subject: [PATCH 3/3] Add the rest of the docs --- .../Authentication/Twitter/src/Messages/RequestToken.cs | 3 +++ .../Authentication/Twitter/src/TwitterDefaults.cs | 9 +++++++++ .../Authentication/Twitter/src/TwitterExtensions.cs | 6 +++--- .../Twitter/src/TwitterPostConfigureOptions.cs | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Security/Authentication/Twitter/src/Messages/RequestToken.cs b/src/Security/Authentication/Twitter/src/Messages/RequestToken.cs index f6bd2dc29b5b..5f637fed39b0 100644 --- a/src/Security/Authentication/Twitter/src/Messages/RequestToken.cs +++ b/src/Security/Authentication/Twitter/src/Messages/RequestToken.cs @@ -18,6 +18,9 @@ public class RequestToken /// public string TokenSecret { get; set; } + /// + /// Gets or sets whether the callback was confirmed. + /// public bool CallbackConfirmed { get; set; } /// diff --git a/src/Security/Authentication/Twitter/src/TwitterDefaults.cs b/src/Security/Authentication/Twitter/src/TwitterDefaults.cs index bdab80e59dc3..9b3180b7c860 100644 --- a/src/Security/Authentication/Twitter/src/TwitterDefaults.cs +++ b/src/Security/Authentication/Twitter/src/TwitterDefaults.cs @@ -3,10 +3,19 @@ namespace Microsoft.AspNetCore.Authentication.Twitter { + /// + /// Default values for the Twitter authentication handler. + /// public static class TwitterDefaults { + /// + /// The default scheme for Twitter authentication. The value is Twitter. + /// public const string AuthenticationScheme = "Twitter"; + /// + /// The default display name for Twitter authentication. Defaults to Twitter. + /// public static readonly string DisplayName = "Twitter"; // https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token diff --git a/src/Security/Authentication/Twitter/src/TwitterExtensions.cs b/src/Security/Authentication/Twitter/src/TwitterExtensions.cs index e0b64af54a87..7caf13488a0f 100644 --- a/src/Security/Authentication/Twitter/src/TwitterExtensions.cs +++ b/src/Security/Authentication/Twitter/src/TwitterExtensions.cs @@ -34,7 +34,7 @@ public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builde /// /// /// The . - /// A delegate to configure . + /// A delegate to configure . /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, Action configureOptions) => builder.AddTwitter(TwitterDefaults.AuthenticationScheme, configureOptions); @@ -48,7 +48,7 @@ public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builde /// /// The . /// The authentication scheme. - /// A delegate to configure . + /// A delegate to configure . /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, Action configureOptions) => builder.AddTwitter(authenticationScheme, TwitterDefaults.DisplayName, configureOptions); @@ -63,7 +63,7 @@ public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builde /// The . /// The authentication scheme. /// A display name for the authentication handler. - /// A delegate to configure . + /// A delegate to configure . /// A reference to after the operation has completed. public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action configureOptions) { diff --git a/src/Security/Authentication/Twitter/src/TwitterPostConfigureOptions.cs b/src/Security/Authentication/Twitter/src/TwitterPostConfigureOptions.cs index 09db5699f9c3..91b6eeedebd0 100644 --- a/src/Security/Authentication/Twitter/src/TwitterPostConfigureOptions.cs +++ b/src/Security/Authentication/Twitter/src/TwitterPostConfigureOptions.cs @@ -14,6 +14,10 @@ public class TwitterPostConfigureOptions : IPostConfigureOptions { private readonly IDataProtectionProvider _dp; + /// + /// Initializes the . + /// + /// The . public TwitterPostConfigureOptions(IDataProtectionProvider dataProtection) { _dp = dataProtection;