Skip to content

Commit cccf56b

Browse files
mariozskikevinchalet
authored andcommitted
Fix templates and add missing XML documentation
1 parent ce40d43 commit cccf56b

File tree

6 files changed

+49
-22
lines changed

6 files changed

+49
-22
lines changed

generators/app/templates/AuthenticationExtensions.cs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,57 @@
66

77
using System;
88
using AspNet.Security.OAuth.<%= name %>;
9-
using Microsoft.Extensions.Internal;
9+
using JetBrains.Annotations;
10+
using Microsoft.Extensions.Options;
1011

11-
namespace Microsoft.AspNet.Builder {
12+
namespace Microsoft.AspNetCore.Builder {
13+
/// <summary>
14+
/// Extension methods to add <%= name %> authentication capabilities to an HTTP application pipeline.
15+
/// </summary>
1216
public static class <%= name %>AuthenticationExtensions {
17+
/// <summary>
18+
/// Adds the <see cref="<%= name %>AuthenticationMiddleware"/> middleware to the specified
19+
/// <see cref="IApplicationBuilder"/>, which enables <%= name %> authentication capabilities.
20+
/// </summary>
21+
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
22+
/// <param name="options">A <see cref="<%= name %>AuthenticationOptions"/> that specifies options for the middleware.</param>
23+
/// <returns>A reference to this instance after the operation has completed.</returns>
1324
public static IApplicationBuilder Use<%= name %>Authentication(
1425
[NotNull] this IApplicationBuilder app,
1526
[NotNull] <%= name %>AuthenticationOptions options) {
16-
return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(options);
27+
if (app == null) {
28+
throw new ArgumentNullException(nameof(app));
29+
}
30+
31+
if (options == null) {
32+
throw new ArgumentNullException(nameof(options));
33+
}
34+
35+
return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(Options.Create(options));
1736
}
1837

38+
/// <summary>
39+
/// Adds the <see cref="<%= name %>AuthenticationMiddleware"/> middleware to the specified
40+
/// <see cref="IApplicationBuilder"/>, which enables <%= name %> authentication capabilities.
41+
/// </summary>
42+
/// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
43+
/// <param name="configuration">An action delegate to configure the provided <see cref="<%= name %>AuthenticationOptions"/>.</param>
44+
/// <returns>A reference to this instance after the operation has completed.</returns>
1945
public static IApplicationBuilder Use<%= name %>Authentication(
2046
[NotNull] this IApplicationBuilder app,
2147
[NotNull] Action<<%= name %>AuthenticationOptions> configuration) {
48+
if (app == null) {
49+
throw new ArgumentNullException(nameof(app));
50+
}
51+
52+
if (configuration == null) {
53+
throw new ArgumentNullException(nameof(configuration));
54+
}
55+
2256
var options = new <%= name %>AuthenticationOptions();
2357
configuration(options);
2458

25-
return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(options);
59+
return app.UseMiddleware<<%= name %>AuthenticationMiddleware>(Options.Create(options));
2660
}
2761
}
2862
}

generators/app/templates/AuthenticationHandler.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,13 @@ protected override async Task<AuthenticationTicket> CreateTicketAsync([NotNull]
3838
// TODO: Add any optional claims, eg
3939
// .AddOptionalClaim("urn:<%= name.toLowerCase() %>:name", <%= name %>AuthenticationHelper.GetName(payload), Options.ClaimsIssuer)
4040

41-
var context = new OAuthCreatingTicketContext(Context, Options, Backchannel, tokens, payload) {
42-
Principal = new ClaimsPrincipal(identity),
43-
Properties = properties
44-
};
41+
var principal = new ClaimsPrincipal(identity);
42+
var ticket = new AuthenticationTicket(principal, properties, Options.AuthenticationScheme);
4543

44+
var context = new OAuthCreatingTicketContext(ticket, Context, Options, Backchannel, tokens, payload);
4645
await Options.Events.CreatingTicket(context);
4746

48-
if (context.Principal?.Identity == null) {
49-
return null;
50-
}
51-
52-
return new AuthenticationTicket(context.Principal, context.Properties, context.Options.AuthenticationScheme);
47+
return context.Ticket;
5348
}
5449
}
5550
}

generators/app/templates/AuthenticationMiddleware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ namespace AspNet.Security.OAuth.<%= name %> {
1717
public class <%= name %>AuthenticationMiddleware : OAuthMiddleware<<%= name %>AuthenticationOptions> {
1818
public <%= name %>AuthenticationMiddleware(
1919
[NotNull] RequestDelegate next,
20-
[NotNull] <%= name %>AuthenticationOptions options,
2120
[NotNull] IDataProtectionProvider dataProtectionProvider,
2221
[NotNull] ILoggerFactory loggerFactory,
2322
[NotNull] UrlEncoder encoder,
24-
[NotNull] IOptions<SharedAuthenticationOptions> externalOptions)
25-
: base(next, dataProtectionProvider, loggerFactory, encoder, externalOptions, options) {
23+
[NotNull] IOptions<SharedAuthenticationOptions> sharedOptions,
24+
[NotNull] IOptions<<%= name %>AuthenticationOptions> options)
25+
: base(next, dataProtectionProvider, loggerFactory, encoder, sharedOptions, options) {
2626
}
2727

2828
protected override AuthenticationHandler<<%= name %>AuthenticationOptions> CreateHandler() {

generators/app/templates/AuthenticationOptions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public class <%= name %>AuthenticationOptions : OAuthOptions {
2222
AuthorizationEndpoint = <%= name %>AuthenticationDefaults.AuthorizationEndpoint;
2323
TokenEndpoint = <%= name %>AuthenticationDefaults.TokenEndpoint;
2424
UserInformationEndpoint = <%= name %>AuthenticationDefaults.UserInformationEndpoint;
25-
26-
SaveTokensAsClaims = false;
2725
}
2826
}
2927
}

generators/app/templates/project.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"version": "1.0.0-*",
3-
"description": "ASP.NET 5 security middleware enabling <%= name %> authentication.",
2+
"version": "1.0.0-beta2-*",
3+
"description": "ASP.NET Core security middleware enabling <%= name %> authentication.",
44
"authors": [ "<%= authorname %>" ],
55

66
"packOptions": {
@@ -33,7 +33,7 @@
3333
"dependencies": {
3434
"AspNet.Security.OAuth.Extensions": { "target": "project", "type": "build" },
3535
"JetBrains.Annotations": { "type": "build", "version": "10.1.4" },
36-
"Microsoft.AspNetCore.Authentication.OAuth": "1.0.0-*"
36+
"Microsoft.AspNetCore.Authentication.OAuth": "1.0.0"
3737
},
3838

3939
"frameworks": {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "generator-aspnet-oauth",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"description": "Yeoman generator for OAuth Providers for ASP.NET 5",
55
"license": "MIT",
66
"main": "app/index.js",

0 commit comments

Comments
 (0)