generator-aspnet-oauth 5.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generators/app/index.js +83 -37
- package/generators/app/templates/AuthenticationDefaults.cs +37 -41
- package/generators/app/templates/AuthenticationExtensions.cs +57 -61
- package/generators/app/templates/AuthenticationHandler.cs +60 -51
- package/generators/app/templates/AuthenticationOptions.cs +17 -20
- package/generators/app/templates/Project.csproj +6 -0
- package/package.json +12 -5
package/generators/app/index.js
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
const fetch = require('cross-fetch');
|
|
3
|
+
const Generator = require('yeoman-generator');
|
|
4
|
+
const queryString = require('query-string');
|
|
5
|
+
const yosay = require('yosay');
|
|
5
6
|
|
|
6
|
-
module.exports =
|
|
7
|
-
initializing: function() {
|
|
8
|
-
this.templatedata = {};
|
|
7
|
+
module.exports = class extends Generator {
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var done = this.async();
|
|
9
|
+
initializing() {
|
|
10
|
+
this.templateData = {};
|
|
11
|
+
this.log(yosay('Welcome to the classy ASP.NET OAuth Provider generator!'));
|
|
12
|
+
}
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
async prompting() {
|
|
15
|
+
const prompts = [{
|
|
17
16
|
type: 'input',
|
|
18
17
|
name: 'name',
|
|
19
18
|
message: 'What is the name of the provider you want to create?',
|
|
@@ -44,29 +43,76 @@ module.exports = yeoman.generators.Base.extend({
|
|
|
44
43
|
store: true
|
|
45
44
|
}];
|
|
46
45
|
|
|
47
|
-
this.prompt(prompts
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
writing
|
|
62
|
-
this.fs.copyTpl(this.templatePath('Project.csproj'), this.
|
|
63
|
-
this.fs.copyTpl(this.templatePath('AuthenticationDefaults.cs'), this.
|
|
64
|
-
this.fs.copyTpl(this.templatePath('AuthenticationExtensions.cs'), this.
|
|
65
|
-
this.fs.copyTpl(this.templatePath('AuthenticationHandler.cs'), this.
|
|
66
|
-
this.fs.copyTpl(this.templatePath('AuthenticationOptions.cs'), this.
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
const answers = await this.prompt(prompts);
|
|
47
|
+
|
|
48
|
+
this.templateData.name = answers.name;
|
|
49
|
+
this.templateData.authorname = answers.authorname;
|
|
50
|
+
this.templateData.authorizationendpoint = answers.authorizationendpoint;
|
|
51
|
+
this.templateData.tokenendpoint = answers.tokenendpoint;
|
|
52
|
+
this.templateData.userinformationendpoint = answers.userinformationendpoint;
|
|
53
|
+
|
|
54
|
+
this.templateData.currentVersion = await this.getCurrentVersion();
|
|
55
|
+
|
|
56
|
+
this.name = answers.name;
|
|
57
|
+
this.applicationName = 'AspNet.Security.OAuth.' + answers.name;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
writing() {
|
|
61
|
+
this.fs.copyTpl(this.templatePath('Project.csproj'), this.applicationName + '/' + this.applicationName + '.csproj', this.templateData)
|
|
62
|
+
this.fs.copyTpl(this.templatePath('AuthenticationDefaults.cs'), this.applicationName + '/' + this.name + 'AuthenticationDefaults.cs', this.templateData)
|
|
63
|
+
this.fs.copyTpl(this.templatePath('AuthenticationExtensions.cs'), this.applicationName + '/' + this.name + 'AuthenticationExtensions.cs', this.templateData)
|
|
64
|
+
this.fs.copyTpl(this.templatePath('AuthenticationHandler.cs'), this.applicationName + '/' + this.name + 'AuthenticationHandler.cs', this.templateData)
|
|
65
|
+
this.fs.copyTpl(this.templatePath('AuthenticationOptions.cs'), this.applicationName + '/' + this.name + 'AuthenticationOptions.cs', this.templateData)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async getCurrentVersion() {
|
|
69
|
+
|
|
70
|
+
let response = await fetch('https://api.nuget.org/v3/index.json');
|
|
71
|
+
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
throw new Error(`Failed to query NuGet service index. HTTP status code: ${response.status}.`);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const serviceIndex = await response.json();
|
|
77
|
+
const baseAddress = serviceIndex.resources.find(resource => resource['@type'] === 'SearchQueryService/3.5.0')['@id'];
|
|
78
|
+
|
|
79
|
+
if (!baseAddress) {
|
|
80
|
+
throw new Error('Failed to determine the base address for the NuGet search query service.');
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const query = queryString.stringify({
|
|
84
|
+
prerelease: false,
|
|
85
|
+
q: 'PackageId:AspNet.Security.OAuth.GitHub',
|
|
86
|
+
semVerLevel: '2.0.0',
|
|
87
|
+
take: 1
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
const searchUrl = `${baseAddress}?${query}`;
|
|
91
|
+
response = await fetch(searchUrl);
|
|
92
|
+
|
|
93
|
+
if (!response.ok) {
|
|
94
|
+
throw new Error(`Failed to search for NuGet package from '${searchUrl}'. HTTP status code: ${response.status}.`);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const searchResult = await response.json();
|
|
98
|
+
|
|
99
|
+
let latestVersion = null;
|
|
100
|
+
|
|
101
|
+
if (searchResult.data && searchResult.data.length > 0) {
|
|
102
|
+
latestVersion = searchResult.data[0].version;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!latestVersion) {
|
|
106
|
+
throw new Error('Failed to determine the latest version of the OAuth providers.');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const dot = '.';
|
|
110
|
+
const versionParts = latestVersion.split(dot);
|
|
111
|
+
|
|
112
|
+
// Increment the build number by one for the release that
|
|
113
|
+
// would be the first one including this new provider.
|
|
114
|
+
versionParts[2] = parseInt(versionParts[2], 10) + 1;
|
|
115
|
+
|
|
116
|
+
return versionParts.join(dot);
|
|
71
117
|
}
|
|
72
|
-
}
|
|
118
|
+
};
|
|
@@ -4,49 +4,45 @@
|
|
|
4
4
|
* for more information concerning the license and the contributors participating to this project.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
using Microsoft.AspNetCore.Authentication.OAuth;
|
|
7
|
+
namespace AspNet.Security.OAuth.<%= name %>;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
/// <summary>
|
|
10
|
+
/// Default values used by the <%= name %> authentication provider.
|
|
11
|
+
/// </summary>
|
|
12
|
+
public static class <%= name %>AuthenticationDefaults
|
|
11
13
|
{
|
|
12
14
|
/// <summary>
|
|
13
|
-
/// Default
|
|
15
|
+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
|
|
14
16
|
/// </summary>
|
|
15
|
-
public
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
/// <summary>
|
|
48
|
-
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
|
|
49
|
-
/// </summary>
|
|
50
|
-
public const string UserInformationEndpoint = "<%= userinformationendpoint %>";
|
|
51
|
-
}
|
|
17
|
+
public const string AuthenticationScheme = "<%= name %>";
|
|
18
|
+
|
|
19
|
+
/// <summary>
|
|
20
|
+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
|
|
21
|
+
/// </summary>
|
|
22
|
+
public static readonly string DisplayName = "<%= name %>";
|
|
23
|
+
|
|
24
|
+
/// <summary>
|
|
25
|
+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
|
|
26
|
+
/// </summary>
|
|
27
|
+
public static readonly string Issuer = "<%= name %>";
|
|
28
|
+
|
|
29
|
+
/// <summary>
|
|
30
|
+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
|
|
31
|
+
/// </summary>
|
|
32
|
+
public static readonly string CallbackPath = "/signin-<%= name.toLowerCase() %>";
|
|
33
|
+
|
|
34
|
+
/// <summary>
|
|
35
|
+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
|
|
36
|
+
/// </summary>
|
|
37
|
+
public static readonly string AuthorizationEndpoint = "<%= authorizationendpoint %>";
|
|
38
|
+
|
|
39
|
+
/// <summary>
|
|
40
|
+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
|
|
41
|
+
/// </summary>
|
|
42
|
+
public static readonly string TokenEndpoint = "<%= tokenendpoint %>";
|
|
43
|
+
|
|
44
|
+
/// <summary>
|
|
45
|
+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
|
|
46
|
+
/// </summary>
|
|
47
|
+
public static readonly string UserInformationEndpoint = "<%= userinformationendpoint %>";
|
|
52
48
|
}
|
|
@@ -4,75 +4,71 @@
|
|
|
4
4
|
* for more information concerning the license and the contributors participating to this project.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
using System;
|
|
8
7
|
using AspNet.Security.OAuth.<%= name %>;
|
|
9
|
-
using JetBrains.Annotations;
|
|
10
|
-
using Microsoft.AspNetCore.Authentication;
|
|
11
8
|
|
|
12
|
-
namespace Microsoft.Extensions.DependencyInjection
|
|
9
|
+
namespace Microsoft.Extensions.DependencyInjection;
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Extension methods to add <%= name %> authentication capabilities to an HTTP application pipeline.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public static class <%= name %>AuthenticationExtensions
|
|
13
15
|
{
|
|
14
16
|
/// <summary>
|
|
15
|
-
///
|
|
17
|
+
/// Adds <see cref="<%= name %>AuthenticationHandler"/> to the specified
|
|
18
|
+
/// <see cref="AuthenticationBuilder"/>, which enables <%= name %> authentication capabilities.
|
|
16
19
|
/// </summary>
|
|
17
|
-
|
|
20
|
+
/// <param name="builder">The authentication builder.</param>
|
|
21
|
+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
|
|
22
|
+
public static AuthenticationBuilder Add<%= name %>([NotNull] this AuthenticationBuilder builder)
|
|
18
23
|
{
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/// <see cref="AuthenticationBuilder"/>, which enables <%= name %> authentication capabilities.
|
|
22
|
-
/// </summary>
|
|
23
|
-
/// <param name="builder">The authentication builder.</param>
|
|
24
|
-
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
|
|
25
|
-
public static AuthenticationBuilder Add<%= name %>([NotNull] this AuthenticationBuilder builder)
|
|
26
|
-
{
|
|
27
|
-
return builder.Add<%= name %>(<%= name %>AuthenticationDefaults.AuthenticationScheme, options => { });
|
|
28
|
-
}
|
|
24
|
+
return builder.Add<%= name %>(<%= name %>AuthenticationDefaults.AuthenticationScheme, options => { });
|
|
25
|
+
}
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// Adds <see cref="<%= name %>AuthenticationHandler"/> to the specified
|
|
29
|
+
/// <see cref="AuthenticationBuilder"/>, which enables <%= name %> authentication capabilities.
|
|
30
|
+
/// </summary>
|
|
31
|
+
/// <param name="builder">The authentication builder.</param>
|
|
32
|
+
/// <param name="configuration">The delegate used to configure the <%= name %> options.</param>
|
|
33
|
+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
|
|
34
|
+
public static AuthenticationBuilder Add<%= name %>(
|
|
35
|
+
[NotNull] this AuthenticationBuilder builder,
|
|
36
|
+
[NotNull] Action<<%= name %>AuthenticationOptions> configuration)
|
|
37
|
+
{
|
|
38
|
+
return builder.Add<%= name %>(<%= name %>AuthenticationDefaults.AuthenticationScheme, configuration);
|
|
39
|
+
}
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
/// <summary>
|
|
42
|
+
/// Adds <see cref="<%= name %>AuthenticationHandler"/> to the specified
|
|
43
|
+
/// <see cref="AuthenticationBuilder"/>, which enables <%= name %> authentication capabilities.
|
|
44
|
+
/// </summary>
|
|
45
|
+
/// <param name="builder">The authentication builder.</param>
|
|
46
|
+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
|
|
47
|
+
/// <param name="configuration">The delegate used to configure the <%= name %> options.</param>
|
|
48
|
+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
|
|
49
|
+
public static AuthenticationBuilder Add<%= name %>(
|
|
50
|
+
[NotNull] this AuthenticationBuilder builder,
|
|
51
|
+
[NotNull] string scheme,
|
|
52
|
+
[NotNull] Action<<%= name %>AuthenticationOptions> configuration)
|
|
53
|
+
{
|
|
54
|
+
return builder.Add<%= name %>(scheme, <%= name %>AuthenticationDefaults.DisplayName, configuration);
|
|
55
|
+
}
|
|
59
56
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
57
|
+
/// <summary>
|
|
58
|
+
/// Adds <see cref="<%= name %>AuthenticationHandler"/> to the specified
|
|
59
|
+
/// <see cref="AuthenticationBuilder"/>, which enables <%= name %> authentication capabilities.
|
|
60
|
+
/// </summary>
|
|
61
|
+
/// <param name="builder">The authentication builder.</param>
|
|
62
|
+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
|
|
63
|
+
/// <param name="caption">The optional display name associated with this instance.</param>
|
|
64
|
+
/// <param name="configuration">The delegate used to configure the <%= name %> options.</param>
|
|
65
|
+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
|
|
66
|
+
public static AuthenticationBuilder Add<%= name %>(
|
|
67
|
+
[NotNull] this AuthenticationBuilder builder,
|
|
68
|
+
[NotNull] string scheme,
|
|
69
|
+
[CanBeNull] string caption,
|
|
70
|
+
[NotNull] Action<<%= name %>AuthenticationOptions> configuration)
|
|
71
|
+
{
|
|
72
|
+
return builder.AddOAuth<<%= name %>AuthenticationOptions, <%= name %>AuthenticationHandler>(scheme, caption, configuration);
|
|
77
73
|
}
|
|
78
74
|
}
|
|
@@ -9,74 +9,83 @@ using System.Net.Http.Headers;
|
|
|
9
9
|
using System.Security.Claims;
|
|
10
10
|
using System.Text.Encodings.Web;
|
|
11
11
|
using System.Text.Json;
|
|
12
|
-
using System.Threading.Tasks;
|
|
13
|
-
using JetBrains.Annotations;
|
|
14
|
-
using Microsoft.AspNetCore.Authentication;
|
|
15
|
-
using Microsoft.AspNetCore.Authentication.OAuth;
|
|
16
12
|
using Microsoft.AspNetCore.WebUtilities;
|
|
17
13
|
using Microsoft.Extensions.Logging;
|
|
18
14
|
using Microsoft.Extensions.Options;
|
|
19
15
|
|
|
20
|
-
namespace AspNet.Security.OAuth.<%= name
|
|
16
|
+
namespace AspNet.Security.OAuth.<%= name %>;
|
|
17
|
+
|
|
18
|
+
/// <summary>
|
|
19
|
+
/// Defines a handler for authentication using <%= name %>.
|
|
20
|
+
/// </summary>
|
|
21
|
+
public partial class <%= name %>AuthenticationHandler : OAuthHandler<<%= name %>AuthenticationOptions>
|
|
21
22
|
{
|
|
22
23
|
/// <summary>
|
|
23
|
-
///
|
|
24
|
+
/// Initializes a new instance of the <see cref="<%= name %>AuthenticationHandler"/> class.
|
|
24
25
|
/// </summary>
|
|
25
|
-
|
|
26
|
+
/// <param name="options">The authentication options.</param>
|
|
27
|
+
/// <param name="logger">The logger to use.</param>
|
|
28
|
+
/// <param name="encoder">The URL encoder to use.</param>
|
|
29
|
+
/// <param name="clock">The system clock to use.</param>
|
|
30
|
+
public <%= name %>AuthenticationHandler(
|
|
31
|
+
[NotNull] IOptionsMonitor<<%= name %>AuthenticationOptions> options,
|
|
32
|
+
[NotNull] ILoggerFactory logger,
|
|
33
|
+
[NotNull] UrlEncoder encoder,
|
|
34
|
+
[NotNull] ISystemClock clock)
|
|
35
|
+
: base(options, logger, encoder, clock)
|
|
26
36
|
{
|
|
27
|
-
|
|
28
|
-
/// Initializes a new instance of the <see cref="<%= name %>AuthenticationHandler"/> class.
|
|
29
|
-
/// </summary>
|
|
30
|
-
/// <param name="options">The authentication options.</param>
|
|
31
|
-
/// <param name="logger">The logger to use.</param>
|
|
32
|
-
/// <param name="encoder">The URL encoder to use.</param>
|
|
33
|
-
/// <param name="clock">The system clock to use.</param>
|
|
34
|
-
public <%= name %>AuthenticationHandler(
|
|
35
|
-
[NotNull] IOptionsMonitor<<%= name %>AuthenticationOptions> options,
|
|
36
|
-
[NotNull] ILoggerFactory logger,
|
|
37
|
-
[NotNull] UrlEncoder encoder,
|
|
38
|
-
[NotNull] ISystemClock clock)
|
|
39
|
-
: base(options, logger, encoder, clock)
|
|
40
|
-
{
|
|
41
|
-
}
|
|
37
|
+
}
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
/// <inheritdoc />
|
|
40
|
+
protected override async Task<AuthenticationTicket> CreateTicketAsync(
|
|
41
|
+
[NotNull] ClaimsIdentity identity,
|
|
42
|
+
[NotNull] AuthenticationProperties properties,
|
|
43
|
+
[NotNull] OAuthTokenResponse tokens)
|
|
44
|
+
{
|
|
45
|
+
var endpoint = Options.UserInformationEndpoint;
|
|
50
46
|
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
// TODO Append any additional query string parameters required
|
|
48
|
+
////endpoint = QueryHelpers.AddQueryString(endpoint, "token", tokens.AccessToken);
|
|
53
49
|
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
using var request = new HttpRequestMessage(HttpMethod.Get, endpoint);
|
|
51
|
+
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
// TODO Add any HTTP request headers required
|
|
54
|
+
////request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
|
|
59
55
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
/* Headers: */ response.Headers.ToString(),
|
|
67
|
-
/* Body: */ await response.Content.ReadAsStringAsync());
|
|
56
|
+
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
|
|
57
|
+
if (!response.IsSuccessStatusCode)
|
|
58
|
+
{
|
|
59
|
+
await Log.UserProfileErrorAsync(Logger, response, Context.RequestAborted);
|
|
60
|
+
throw new HttpRequestException("An error occurred while retrieving the user profile from <%= name %>.");
|
|
61
|
+
}
|
|
68
62
|
|
|
69
|
-
|
|
70
|
-
}
|
|
63
|
+
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
|
71
64
|
|
|
72
|
-
|
|
65
|
+
var principal = new ClaimsPrincipal(identity);
|
|
66
|
+
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
|
|
67
|
+
context.RunClaimActions();
|
|
73
68
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
await Events.CreatingTicket(context);
|
|
70
|
+
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
|
|
71
|
+
}
|
|
77
72
|
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
private static partial class Log
|
|
74
|
+
{
|
|
75
|
+
internal static async Task UserProfileErrorAsync(ILogger logger, HttpResponseMessage response, CancellationToken cancellationToken)
|
|
76
|
+
{
|
|
77
|
+
UserProfileError(
|
|
78
|
+
logger,
|
|
79
|
+
response.StatusCode,
|
|
80
|
+
response.Headers.ToString(),
|
|
81
|
+
await response.Content.ReadAsStringAsync(cancellationToken));
|
|
80
82
|
}
|
|
83
|
+
|
|
84
|
+
[LoggerMessage(1, LogLevel.Error, "An error occurred while retrieving the user profile: the remote server returned a {Status} response with the following payload: {Headers} {Body}.")]
|
|
85
|
+
private static partial void UserProfileError(
|
|
86
|
+
ILogger logger,
|
|
87
|
+
System.Net.HttpStatusCode status,
|
|
88
|
+
string headers,
|
|
89
|
+
string body);
|
|
81
90
|
}
|
|
82
91
|
}
|
|
@@ -5,33 +5,30 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
using System.Security.Claims;
|
|
8
|
-
using Microsoft.AspNetCore.Authentication;
|
|
9
|
-
using Microsoft.AspNetCore.Authentication.OAuth;
|
|
10
8
|
|
|
11
|
-
namespace AspNet.Security.OAuth.<%= name
|
|
9
|
+
namespace AspNet.Security.OAuth.<%= name %>;
|
|
10
|
+
|
|
11
|
+
/// <summary>
|
|
12
|
+
/// Defines a set of options used by <see cref="<%= name %>AuthenticationHandler"/>.
|
|
13
|
+
/// </summary>
|
|
14
|
+
public class <%= name %>AuthenticationOptions : OAuthOptions
|
|
12
15
|
{
|
|
13
16
|
/// <summary>
|
|
14
|
-
///
|
|
17
|
+
/// Initializes a new instance of the <see cref="<%= name %>AuthenticationOptions"/> class.
|
|
15
18
|
/// </summary>
|
|
16
|
-
public
|
|
19
|
+
public <%= name %>AuthenticationOptions()
|
|
17
20
|
{
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/// </summary>
|
|
21
|
-
public <%= name %>AuthenticationOptions()
|
|
22
|
-
{
|
|
23
|
-
ClaimsIssuer = <%= name %>AuthenticationDefaults.Issuer;
|
|
24
|
-
CallbackPath = <%= name %>AuthenticationDefaults.CallbackPath;
|
|
21
|
+
ClaimsIssuer = <%= name %>AuthenticationDefaults.Issuer;
|
|
22
|
+
CallbackPath = <%= name %>AuthenticationDefaults.CallbackPath;
|
|
25
23
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
AuthorizationEndpoint = <%= name %>AuthenticationDefaults.AuthorizationEndpoint;
|
|
25
|
+
TokenEndpoint = <%= name %>AuthenticationDefaults.TokenEndpoint;
|
|
26
|
+
UserInformationEndpoint = <%= name %>AuthenticationDefaults.UserInformationEndpoint;
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
// TODO Add any required scopes
|
|
29
|
+
// Scope.Add("?");
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
31
|
+
// TODO Map any claims
|
|
32
|
+
// ClaimActions.MapJsonKey(ClaimTypes.Email, "?");
|
|
36
33
|
}
|
|
37
34
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
<Project Sdk="Microsoft.NET.Sdk">
|
|
2
2
|
|
|
3
3
|
<PropertyGroup>
|
|
4
|
+
<PackageValidationBaselineVersion><%= currentVersion %></PackageValidationBaselineVersion>
|
|
4
5
|
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
|
|
5
6
|
</PropertyGroup>
|
|
6
7
|
|
|
8
|
+
<!-- This property group is required until the new provider is first published to NuGet.org -->
|
|
9
|
+
<PropertyGroup>
|
|
10
|
+
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
|
|
11
|
+
</PropertyGroup>
|
|
12
|
+
|
|
7
13
|
<PropertyGroup>
|
|
8
14
|
<Description>ASP.NET Core security provider enabling <%= name %> authentication.</Description>
|
|
9
15
|
<Authors><%= authorname %></Authors>
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "generator-aspnet-oauth",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"description": "Yeoman generator for OAuth Providers for ASP.NET Core",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "app/index.js",
|
|
7
7
|
"repository": "aspnet-contrib/generator-aspnet-oauth",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=14"
|
|
10
|
+
},
|
|
8
11
|
"author": {
|
|
9
12
|
"name": "Jerrie Pelser",
|
|
10
13
|
"email": "jerrie@jerriepelser.com",
|
|
@@ -23,11 +26,15 @@
|
|
|
23
26
|
"oauth"
|
|
24
27
|
],
|
|
25
28
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"yosay": "^
|
|
29
|
+
"cross-fetch": "^3.1.5",
|
|
30
|
+
"query-string": "^7.1.1",
|
|
31
|
+
"yosay": "^2.0.2",
|
|
32
|
+
"yeoman-generator": "^5.7.0"
|
|
29
33
|
},
|
|
30
34
|
"devDependencies": {
|
|
31
|
-
"
|
|
35
|
+
"glob": "^8.0.3",
|
|
36
|
+
"mocha": "^10.1.0",
|
|
37
|
+
"yeoman-assert": "^3.1.1",
|
|
38
|
+
"yeoman-test": "^6.3.0"
|
|
32
39
|
}
|
|
33
40
|
}
|