Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log out user after approve or reject system user request #421

Merged
merged 24 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
be0c309
add redirect page for testing
mgunnerud Oct 1, 2024
d5e5a8c
move redirect request
mgunnerud Oct 8, 2024
d0aca1c
move requestId to query param
mgunnerud Oct 8, 2024
c452f3a
add new endpoint for unauthorized redirect
mgunnerud Oct 16, 2024
bc73ce3
Merge remote-tracking branch 'origin/main' into 748-utlogging-og-redi…
mgunnerud Oct 16, 2024
3fef719
testcode
mgunnerud Oct 16, 2024
365a9be
rename param
mgunnerud Oct 16, 2024
9ed9f03
Merge remote-tracking branch 'origin/main' into 748-utlogging-og-redi…
mgunnerud Oct 16, 2024
f24e76c
return error if redirectUrl is not found
mgunnerud Oct 17, 2024
1d73580
Merge remote-tracking branch 'origin/main' into 748-utlogging-og-redi…
mgunnerud Oct 17, 2024
6fba402
fix API route
mgunnerud Oct 17, 2024
1fafbf0
change from POST to GET
mgunnerud Oct 17, 2024
3ad30ea
Merge remote-tracking branch 'origin/main' into 748-utlogging-og-redi…
mgunnerud Nov 1, 2024
7ed7678
call logout endpoint in Altinn 3
mgunnerud Nov 1, 2024
b5787c0
refactor
mgunnerud Nov 11, 2024
863980d
set cookie for superdomain
mgunnerud Nov 11, 2024
12012c9
fix query param name
mgunnerud Nov 11, 2024
9dbad44
clean up cookie after reading value
mgunnerud Nov 11, 2024
00aee4b
remove call to load redirect url
mgunnerud Nov 12, 2024
502f067
remove unused model
mgunnerud Nov 12, 2024
8c1175b
Merge branch 'main' into 748-utlogging-og-redirect-til-leverandr
mgunnerud Nov 13, 2024
2cc0a72
fix url
mgunnerud Nov 13, 2024
58605c4
Merge branch '748-utlogging-og-redirect-til-leverandr' of https://git…
mgunnerud Nov 13, 2024
09e88a0
Merge branch 'main' into 748-utlogging-og-redirect-til-leverandr
mgunnerud Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Altinn.Authentication.UI.Core.Authentication;
using Altinn.Authentication.UI.Core.AppConfiguration;
using Altinn.Authentication.UI.Core.Authentication;
using Altinn.Authentication.UI.Core.SystemUsers;
using Altinn.Authentication.UI.Filters;
using Altinn.Authentication.UI.Integration.Configuration;
using Altinn.Authorization.ProblemDetails;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http.Headers;
using Microsoft.Extensions.Options;

/// <summary>
/// API for the Frontend to fetch a Request then reject or approve it.
Expand All @@ -15,7 +17,7 @@
[ApiController]
[AutoValidateAntiforgeryTokenIfAuthCookie]
public class RequestController(
IRequestService _requestService) : ControllerBase
IRequestService _requestService, IOptions<PlatformSettings> _platformSettings, IOptions<GeneralSettings> _generalSettings) : ControllerBase
{
/// <summary>
/// Gets a VendorRequest by Id
Expand Down Expand Up @@ -85,4 +87,28 @@ public async Task<ActionResult> RejectRequest(Guid requestId, CancellationToken

return Ok(req.Value);
}

/// <summary>
/// Logout
/// </summary>
/// <returns></returns>
[Authorize]
[HttpGet("logout")]
public IActionResult Logout([FromQuery] Guid id)
{
CookieOptions cookieOptions = new()
{
Domain = _generalSettings.Value.HostName,
HttpOnly = true,
Secure = true,
IsEssential = true,
SameSite = SameSiteMode.Lax
};

// store cookie value for redirect
HttpContext.Response.Cookies.Append("AltinnLogoutInfo", $"SystemuserRequestId={id}", cookieOptions);

string logoutUrl = $"{_platformSettings.Value.ApiAuthenticationEndpoint}logout";
return Redirect(logoutUrl);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const VendorRequestPageContent = ({ request, userInfo }: VendorRequestPag
.unwrap()
.then(() => {
if (request.redirectUrl) {
redirectToVendor(request.redirectUrl);
logoutAndRedirectToVendor();
} else {
setIsReceiptVisible(true);
}
Expand All @@ -55,15 +55,15 @@ export const VendorRequestPageContent = ({ request, userInfo }: VendorRequestPag
.unwrap()
.then(() => {
if (request.redirectUrl) {
redirectToVendor(request.redirectUrl);
logoutAndRedirectToVendor();
} else {
logoutUser();
}
});
};

const redirectToVendor = (requestUrl: string): void => {
const url = new URL(requestUrl);
const logoutAndRedirectToVendor = (): void => {
const url = new URL('/authfront/api/v1/systemuser/request/logout', window.location.href);
url.searchParams.append('id', request.id);
window.location.assign(url.toString());
};
Expand Down
Loading