SocialAuthorizeUrl.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Application.Abstractions.Messaging;
  2. using Web.Api.Common;
  3. using Web.Api.Extensions;
  4. namespace Web.Api.Endpoints.Auth;
  5. /// <summary>
  6. /// 소셜 로그인 시작 URL 생성 (Naver/Kakao) — 프론트 start 라우트가 state 생성/쿠키 보관 후 호출.
  7. /// redirectUri 미전달 시 AppSettings OAuth:{Provider}:RedirectUri 사용.
  8. /// </summary>
  9. internal sealed class SocialAuthorizeUrl : IEndpoint
  10. {
  11. public void MapEndpoint(IEndpointRouteBuilder app)
  12. {
  13. app.MapGet("api/auth/{provider}/authorize-url", async (
  14. string provider,
  15. ISender sender,
  16. string? state = null,
  17. string? redirectUri = null,
  18. CancellationToken ct = default
  19. ) => {
  20. var query = new Application.Features.Api.Auth.SocialAuthorizeUrl.Query(
  21. provider,
  22. state ?? string.Empty,
  23. redirectUri
  24. );
  25. var result = await sender.Send(query, ct);
  26. return result.Match(
  27. data => ApiResponse.Ok(data),
  28. CustomResults.Problem
  29. );
  30. })
  31. .WithTags("Auth")
  32. .AllowAnonymous();
  33. }
  34. }