| | | 1 | | using Syki.Back.Auth.Schemes; |
| | | 2 | | using Microsoft.AspNetCore.Authentication; |
| | | 3 | | |
| | | 4 | | namespace Syki.Back.Features.Identity.SocialLoginChallenge; |
| | | 5 | | |
| | | 6 | | [ApiController, EnableRateLimiting(RateLimitingConfigs.SensitivePolicy)] |
| | 0 | 7 | | public class SocialLoginChallengeController(FrontendSettings frontendSettings) : ControllerBase |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Social Login Challenge 🔓 |
| | | 11 | | /// </summary> |
| | | 12 | | /// <remarks> |
| | | 13 | | /// Redirects to the social login provider (Google) for authentication. |
| | | 14 | | /// This is a browser redirect endpoint, not a JSON API. |
| | | 15 | | /// The optional email parameter sets login_hint for the provider. |
| | | 16 | | /// </remarks> |
| | | 17 | | [HttpGet("identity/social-login/challenge/{provider}")] |
| | | 18 | | public IActionResult Challenge(string provider, [FromQuery] string? email = null) |
| | | 19 | | { |
| | 0 | 20 | | Enum.TryParse(provider, ignoreCase: true, out SocialLoginProvider loginProvider); |
| | | 21 | | |
| | 0 | 22 | | var schemeName = loginProvider switch |
| | 0 | 23 | | { |
| | 0 | 24 | | SocialLoginProvider.Google => SocialLoginScheme.GoogleScheme, |
| | 0 | 25 | | _ => null, |
| | 0 | 26 | | }; |
| | | 27 | | |
| | 0 | 28 | | if (schemeName == null) return Redirect($"{frontendSettings.Url}?social_login_error={nameof(SocialLoginFailed)}" |
| | | 29 | | |
| | 0 | 30 | | var properties = new AuthenticationProperties |
| | 0 | 31 | | { |
| | 0 | 32 | | RedirectUri = "/home", |
| | 0 | 33 | | }; |
| | | 34 | | |
| | 0 | 35 | | if (email != null) properties.Items["login_hint"] = email; |
| | | 36 | | |
| | 0 | 37 | | return Challenge(properties, schemeName); |
| | | 38 | | } |
| | | 39 | | } |