| | | 1 | | using Microsoft.AspNetCore.Authentication.Google; |
| | | 2 | | |
| | | 3 | | namespace Syki.Back.Settings; |
| | | 4 | | |
| | | 5 | | public class SocialLoginSettings : SettingsBase |
| | | 6 | | { |
| | 18 | 7 | | public GoogleLoginSettings Google { get; set; } = new(); |
| | | 8 | | |
| | 2 | 9 | | public SocialLoginSettings(IConfiguration configuration) |
| | | 10 | | { |
| | 2 | 11 | | configuration.GetSection("SocialLogin").Bind(this); |
| | | 12 | | |
| | 2 | 13 | | if (Google.Enabled) |
| | | 14 | | { |
| | 2 | 15 | | RequireNonEmpty(Google.ClientId); |
| | 2 | 16 | | RequireNonEmpty(Google.ClientSecret); |
| | | 17 | | } |
| | 2 | 18 | | } |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | public class GoogleLoginSettings |
| | | 22 | | { |
| | | 23 | | public bool Enabled { get; set; } |
| | | 24 | | public string ClientId { get; set; } |
| | | 25 | | public string ClientSecret { get; set; } |
| | | 26 | | public string? TokenEndpoint { get; set; } |
| | | 27 | | public string? AuthorizationEndpoint { get; set; } |
| | | 28 | | public string? UserInformationEndpoint { get; set; } |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public static class SocialLoginSettingsExtensions |
| | | 32 | | { |
| | | 33 | | extension(IConfiguration configuration) |
| | | 34 | | { |
| | | 35 | | public SocialLoginSettings SocialLogin => new(configuration); |
| | | 36 | | } |
| | | 37 | | |
| | | 38 | | extension(GoogleOptions options) |
| | | 39 | | { |
| | | 40 | | public void OverrideWith(GoogleLoginSettings settings) |
| | | 41 | | { |
| | | 42 | | if (settings.AuthorizationEndpoint.HasValue()) |
| | | 43 | | options.AuthorizationEndpoint = settings.AuthorizationEndpoint!; |
| | | 44 | | |
| | | 45 | | if (settings.TokenEndpoint.HasValue()) |
| | | 46 | | options.TokenEndpoint = settings.TokenEndpoint!; |
| | | 47 | | |
| | | 48 | | if (settings.UserInformationEndpoint.HasValue()) |
| | | 49 | | options.UserInformationEndpoint = settings.UserInformationEndpoint!; |
| | | 50 | | } |
| | | 51 | | } |
| | | 52 | | } |