✨ Able to connect with the auth endpoint for oidc
This commit is contained in:
parent
fe04b12561
commit
60a8338c9a
@ -180,8 +180,6 @@ public class ConnectionController(
|
|||||||
|
|
||||||
var accountId = Guid.Parse(stateParts[0]);
|
var accountId = Guid.Parse(stateParts[0]);
|
||||||
return await HandleManualConnection(provider, oidcService, callbackData, accountId);
|
return await HandleManualConnection(provider, oidcService, callbackData, accountId);
|
||||||
|
|
||||||
// Otherwise, it's a login or registration flow.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<IActionResult> HandleManualConnection(string provider, OidcService oidcService,
|
private async Task<IActionResult> HandleManualConnection(string provider, OidcService oidcService,
|
||||||
|
@ -21,16 +21,30 @@ public class OidcController(
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Get the appropriate provider service
|
|
||||||
var oidcService = GetOidcService(provider);
|
var oidcService = GetOidcService(provider);
|
||||||
|
|
||||||
// Generate state (containing return URL) and nonce
|
// If user is already authenticated, treat as an account connection request
|
||||||
var state = returnUrl;
|
if (HttpContext.Items["CurrentUser"] is Account.Account currentUser)
|
||||||
var nonce = Guid.NewGuid().ToString();
|
{
|
||||||
|
var state = Guid.NewGuid().ToString();
|
||||||
|
var nonce = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
// Get the authorization URL and redirect the user
|
// Store user's ID, provider, and nonce in session. The callback will use this.
|
||||||
var authUrl = oidcService.GetAuthorizationUrl(state ?? "/", nonce);
|
HttpContext.Session.SetString($"oidc_state_{state}", $"{currentUser.Id}|{provider}|{nonce}");
|
||||||
return Redirect(authUrl);
|
|
||||||
|
// The state parameter sent to the provider is the GUID key for the session state.
|
||||||
|
var authUrl = oidcService.GetAuthorizationUrl(state, nonce);
|
||||||
|
return Redirect(authUrl);
|
||||||
|
}
|
||||||
|
else // Otherwise, proceed with login/registration flow
|
||||||
|
{
|
||||||
|
var state = returnUrl;
|
||||||
|
var nonce = Guid.NewGuid().ToString();
|
||||||
|
|
||||||
|
// The state parameter is the returnUrl. The callback will not find a session state and will treat it as a login.
|
||||||
|
var authUrl = oidcService.GetAuthorizationUrl(state ?? "/", nonce);
|
||||||
|
return Redirect(authUrl);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user