| | | 1 | | using Microsoft.AspNetCore.Authentication; |
| | | 2 | | using Microsoft.AspNetCore.Authentication.Cookies; |
| | | 3 | | using ProjectTemplate.Web.Authentication.Options; |
| | | 4 | | |
| | | 5 | | namespace ProjectTemplate.Web.Authentication.Providers.GitHub; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Provides extension methods for registering GitHub authentication provider services. |
| | | 9 | | /// </summary> |
| | | 10 | | public static class GitHubAuthenticationServiceExtensions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Adds the GitHub authentication provider registration. |
| | | 14 | | /// </summary> |
| | | 15 | | /// <param name="builder">The authentication builder used to register authentication handlers.</param> |
| | | 16 | | /// <param name="options">The GitHub provider options.</param> |
| | | 17 | | /// <returns>The same <see cref="AuthenticationBuilder"/> instance for chaining.</returns> |
| | | 18 | | public static AuthenticationBuilder AddGitHubAuthentication( |
| | | 19 | | this AuthenticationBuilder builder, |
| | | 20 | | ApplicationExternalAuthenticationProviderOptions options) |
| | | 21 | | { |
| | 186 | 22 | | ArgumentNullException.ThrowIfNull(builder); |
| | 184 | 23 | | ArgumentNullException.ThrowIfNull(options); |
| | | 24 | | |
| | 182 | 25 | | if (!options.Enabled) |
| | | 26 | | { |
| | 174 | 27 | | return builder; |
| | | 28 | | } |
| | | 29 | | |
| | 8 | 30 | | builder.AddGitHub(options.Scheme, options.DisplayName, githubOptions => |
| | 8 | 31 | | { |
| | 2 | 32 | | githubOptions.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; |
| | 2 | 33 | | githubOptions.ClientId = options.ClientId; |
| | 2 | 34 | | githubOptions.ClientSecret = options.ClientSecret; |
| | 2 | 35 | | githubOptions.CallbackPath = options.CallbackPath; |
| | 8 | 36 | | |
| | 20 | 37 | | foreach (string scope in options.Scopes.Where(scope => !string.IsNullOrWhiteSpace(scope))) |
| | 8 | 38 | | { |
| | 4 | 39 | | githubOptions.Scope.Add(scope); |
| | 8 | 40 | | } |
| | 10 | 41 | | }); |
| | | 42 | | |
| | 8 | 43 | | return builder; |
| | | 44 | | } |
| | | 45 | | } |