@@ -10,29 +10,36 @@ namespace OpenShock.API.Controller.OAuth;
1010public sealed partial class OAuthController
1111{
1212 /// <summary>
13- /// Start OAuth authorization for a given provider (login-or-create flow) .
13+ /// Start OAuth authorization for a given provider with the specified flow.
1414 /// </summary>
1515 /// <remarks>
16- /// Initiates an OAuth challenge in "login-or-create" mode.
1716 /// Returns <c>302</c> redirect to the provider authorization page.
1817 /// </remarks>
1918 /// <param name="provider">Provider key (e.g. <c>discord</c>).</param>
19+ /// <param name="flow">Flow to run</param>
2020 /// <response code="302">Redirect to the provider authorization page.</response>
2121 /// <response code="400">Unsupported or misconfigured provider.</response>
2222 [ EnableRateLimiting ( "auth" ) ]
23- [ HttpGet ( "{provider}/authorize" ) ]
23+ [ HttpPost ( "{provider}/authorize" ) ]
2424 [ ProducesResponseType ( StatusCodes . Status302Found ) ]
2525 [ ProducesResponseType < OpenShockProblem > ( StatusCodes . Status400BadRequest , MediaTypeNames . Application . Json ) ]
26- public async Task < IActionResult > OAuthAuthorize ( [ FromRoute ] string provider )
26+ public async Task < IActionResult > OAuthAuthorize ( [ FromRoute ] string provider , [ FromQuery ] OAuthFlow flow )
2727 {
2828 if ( ! await _schemeProvider . IsSupportedOAuthScheme ( provider ) )
2929 return Problem ( OAuthError . UnsupportedProvider ) ;
3030
31- if ( User . HasOpenShockUserIdentity ( ) )
31+ switch ( flow )
3232 {
33- return Problem ( OAuthError . AnonymousOnlyEndpoint ) ;
33+ case OAuthFlow . LoginOrCreate :
34+ if ( User . HasOpenShockUserIdentity ( ) ) return Problem ( OAuthError . FlowRequiresAnonymous ) ;
35+ break ;
36+ case OAuthFlow . Link :
37+ if ( ! User . HasOpenShockUserIdentity ( ) ) return Problem ( OAuthError . FlowRequiresAuthenticatedUser ) ;
38+ break ;
39+ default :
40+ return Problem ( OAuthError . UnsupportedFlow ) ;
3441 }
3542
36- return OAuthUtil . StartOAuth ( provider , OAuthFlow . LoginOrCreate ) ;
43+ return OAuthUtil . StartOAuth ( provider , flow ) ;
3744 }
3845}
0 commit comments