Skip to content

Add API docs to twitter auth #29473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public class RequestToken
/// </summary>
public string TokenSecret { get; set; }

/// <summary>
/// Gets or sets whether the callback was confirmed.
/// </summary>
public bool CallbackConfirmed { get; set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<PropertyGroup>
<Description>ASP.NET Core middleware that enables an application to support Twitter's OAuth 1.0 authentication workflow.</Description>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>aspnetcore;authentication;security</PackageTags>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/Security/Authentication/Twitter/src/TwitterDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@

namespace Microsoft.AspNetCore.Authentication.Twitter
{
/// <summary>
/// Default values for the Twitter authentication handler.
/// </summary>
public static class TwitterDefaults
{
/// <summary>
/// The default scheme for Twitter authentication. The value is <c>Twitter</c>.
/// </summary>
public const string AuthenticationScheme = "Twitter";

/// <summary>
/// The default display name for Twitter authentication. Defaults to <c>Twitter</c>.
/// </summary>
public static readonly string DisplayName = "Twitter";

// https://developer.twitter.com/en/docs/basics/authentication/api-reference/request_token
Expand Down
45 changes: 45 additions & 0 deletions src/Security/Authentication/Twitter/src/TwitterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,62 @@

namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods to configure Twitter OAuth authentication.
/// </summary>
public static class TwitterExtensions
{
/// <summary>
/// Adds Twitter OAuth-based authentication to <see cref="AuthenticationBuilder"/> using the default scheme.
/// The default scheme is specified by <see cref="TwitterDefaults.AuthenticationScheme"/>.
/// <para>
/// Facebook authentication allows application users to sign in with their Facebook account.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
/// <returns>A reference to <paramref name="builder"/> after the operation has completed.</returns>
public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder)
=> builder.AddTwitter(TwitterDefaults.AuthenticationScheme, _ => { });

/// <summary>
/// Adds Twitter OAuth-based authentication to <see cref="AuthenticationBuilder"/> using the default scheme.
/// The default scheme is specified by <see cref="TwitterDefaults.AuthenticationScheme"/>.
/// <para>
/// Facebook authentication allows application users to sign in with their Facebook account.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
/// <param name="configureOptions">A delegate to configure <see cref="TwitterOptions"/>.</param>
/// <returns>A reference to <paramref name="builder"/> after the operation has completed.</returns>
public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, Action<TwitterOptions> configureOptions)
=> builder.AddTwitter(TwitterDefaults.AuthenticationScheme, configureOptions);

/// <summary>
/// Adds Twitter OAuth-based authentication to <see cref="AuthenticationBuilder"/> using the default scheme.
/// The default scheme is specified by <see cref="TwitterDefaults.AuthenticationScheme"/>.
/// <para>
/// Facebook authentication allows application users to sign in with their Facebook account.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
/// <param name="authenticationScheme">The authentication scheme.</param>
/// <param name="configureOptions">A delegate to configure <see cref="TwitterOptions"/>.</param>
/// <returns>A reference to <paramref name="builder"/> after the operation has completed.</returns>
public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, Action<TwitterOptions> configureOptions)
=> builder.AddTwitter(authenticationScheme, TwitterDefaults.DisplayName, configureOptions);

/// <summary>
/// Adds Twitter OAuth-based authentication to <see cref="AuthenticationBuilder"/> using the default scheme.
/// The default scheme is specified by <see cref="TwitterDefaults.AuthenticationScheme"/>.
/// <para>
/// Facebook authentication allows application users to sign in with their Facebook account.
/// </para>
/// </summary>
/// <param name="builder">The <see cref="AuthenticationBuilder"/>.</param>
/// <param name="authenticationScheme">The authentication scheme.</param>
/// <param name="displayName">A display name for the authentication handler.</param>
/// <param name="configureOptions">A delegate to configure <see cref="TwitterOptions"/>.</param>
/// <returns>A reference to <paramref name="builder"/> after the operation has completed.</returns>
public static AuthenticationBuilder AddTwitter(this AuthenticationBuilder builder, string authenticationScheme, string displayName, Action<TwitterOptions> configureOptions)
{
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<TwitterOptions>, TwitterPostConfigureOptions>());
Expand Down
18 changes: 18 additions & 0 deletions src/Security/Authentication/Twitter/src/TwitterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@

namespace Microsoft.AspNetCore.Authentication.Twitter
{
/// <summary>
/// Authentication handler for Twitter's OAuth based authentication.
/// </summary>
public class TwitterHandler : RemoteAuthenticationHandler<TwitterOptions>
{
private static readonly JsonSerializerOptions ErrorSerializerOptions = new JsonSerializerOptions
Expand All @@ -41,12 +44,18 @@ public class TwitterHandler : RemoteAuthenticationHandler<TwitterOptions>
set { base.Events = value; }
}

/// <summary>
/// Initializes a new instance of <see cref="TwitterHandler"/>.
/// </summary>
/// <inheritdoc />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// <inheritdoc />

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that this copies the param docs, I copied this from the facebook handler ctor

public TwitterHandler(IOptionsMonitor<TwitterOptions> options, ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
: base(options, logger, encoder, clock)
{ }

/// <inheritdoc />
protected override Task<object> CreateEventsAsync() => Task.FromResult<object>(new TwitterEvents());

/// <inheritdoc />
protected override async Task<HandleRequestResult> HandleRemoteAuthenticateAsync()
{
var query = Request.Query;
Expand Down Expand Up @@ -130,6 +139,14 @@ protected override async Task<HandleRequestResult> HandleRemoteAuthenticateAsync
}
}

/// <summary>
/// Creates an <see cref="AuthenticationTicket"/> from the specified <paramref name="token"/>.
/// </summary>
/// <param name="identity">The <see cref="ClaimsIdentity"/>.</param>
/// <param name="properties">The <see cref="AuthenticationProperties"/>.</param>
/// <param name="token">The <see cref="AccessToken"/>.</param>
/// <param name="user">The <see cref="JsonElement"/> for the user.</param>
/// <returns>The <see cref="AuthenticationTicket"/>.</returns>
protected virtual async Task<AuthenticationTicket> CreateTicketAsync(
ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token, JsonElement user)
{
Expand All @@ -144,6 +161,7 @@ protected virtual async Task<AuthenticationTicket> CreateTicketAsync(
return new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name);
}

/// <inheritdoc />
protected override async Task HandleChallengeAsync(AuthenticationProperties properties)
{
if (string.IsNullOrEmpty(properties.RedirectUri))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public class TwitterPostConfigureOptions : IPostConfigureOptions<TwitterOptions>
{
private readonly IDataProtectionProvider _dp;

/// <summary>
/// Initializes the <see cref="TwitterPostConfigureOptions"/>.
/// </summary>
/// <param name="dataProtection">The <see cref="IDataProtectionProvider"/>.</param>
public TwitterPostConfigureOptions(IDataProtectionProvider dataProtection)
{
_dp = dataProtection;
Expand Down