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

Revoke apple token usage #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<quarkus.platform.group-id>io.quarkus</quarkus.platform.group-id>
<quarkus.platform.version>3.8.3</quarkus.platform.version>
<surefire-plugin.version>3.0.0-M5</surefire-plugin.version>
<renarde.version>3.0.9</renarde.version>
<renarde.version>3.0.12-SNAPSHOT</renarde.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ main.help=Help
main.about=About
main.language=Language
main.logout=Logout
main.revoke=Revoke
main.backoffice=Backoffice
main.todos=Todos

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages_fr.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ main.help=Aide
main.about=À propos
main.language=Langue
main.logout=Déconnexion
main.revoke=Suppression
main.backoffice=Administration
main.todos=Tâches

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/templates/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li class="nav-item"><a class="nav-link" aria-current="page" href="/_renarde/backoffice/index"><i class="bi bi-database"></i>{m:main.backoffice}</a></li>
{/if}
<li class="nav-item"><a class="nav-link" aria-current="page" href="{uri:RenardeSecurityController.logout()}">{m:main.logout}</a></li>
{#if inject:user.tenantId && inject:user.tenantId is 'apple'}
<li class="nav-item"><a class="nav-link" aria-current="page" href="{uri:RenardeRevokeController.revokeApple()}" >{m:main.revoke}</a></li>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is the right thing to show/do.

The original requirement from Apple is that it be possible to delete an account, and that deleting an account should revoke the tokens.

So I don't think this is the functionality we should expose, as it does not delete the local account (the User instance in the DB).

There should be an option to delete your account, probably with an intermediate page with a "Are you really sure?" button, and that should delete the account, and revoke the tokens, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, we must also delete the user on our db, not only the apple access.
Don't you think we need an User detail page to place this new button (and not in the top menu) ?
For instance, a link on the user name in the top bar that open a page which display user info plus a revoke/delete account button.
Also, I'll need a custom endpoint on this Todo project to handle de DB deletion of the user. I can do that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, I missed this.

Yes, you're right, it makes sense to add an account page, and put the delete button there.

{/if}
{/if}
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/fr/epardaud/TodoResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,67 @@ public void appleLoginTest() {
"Foo", "Bar", "AppleUser", "[email protected]", "q_session_apple");
}

@Test
public void appleRevokeTest(){
// GIVEN a registered apple user
RenardeCookieFilter cookieFilter = new RenardeCookieFilter();
ValidatableResponse response = follow("/_renarde/security/login-apple", cookieFilter);
JsonPath json = response.statusCode(200)
.extract().body().jsonPath();
String code = json.get("code");
String state = json.get("state");

String location = given()
.when()
.filter(cookieFilter)
.formParam("state", state)
.formParam("code", code)
// can't follow redirects due to cookies
.redirects().follow(false)
// must be precise and not contain an encoding: probably needs fixing in the OIDC side
.contentType("application/x-www-form-urlencoded")
.log().ifValidationFails()
.post("/_renarde/security/oidc-success")
.then()
.log().ifValidationFails()
.statusCode(302)
.extract().header("Location");
follow(location.replace("https://", "http://"), cookieFilter)
.body(containsString("Complete registration for [email protected]"));

// WHEN Revoke access
List<String> setCookieHeaderResp = given()
.when()
.filter(cookieFilter)
.redirects().follow(false)
.get("/_renarde/security/apple-revoke")
.then()
.statusCode(303)
.extract().headers()
.getValues("Set-Cookie");

// THEN Cookie is reset (no more QuarkusUser nor apple session)
String userLogoutCookie = setCookieHeaderResp.stream()
.filter(c -> c.startsWith("QuarkusUser="))
.findFirst()
.orElseThrow();
Assertions.assertEquals("QuarkusUser=;Version=1;Path=/;Max-Age=0", userLogoutCookie);
String userSessionCookie = setCookieHeaderResp.stream()
.filter(c -> c.startsWith("q_session_apple="))
.findFirst()
.orElseThrow();
Assertions.assertEquals("q_session_apple=;Version=1;Path=/;Max-Age=0", userSessionCookie);

// THEN Secure page will redirect to login
Assertions.assertTrue(
given().when().filter(cookieFilter)
.redirects().follow(false)
.get("/Todos/index")
.then()
.statusCode(302).extract().header("Location")
.endsWith("Login/login"));
}

private void finishConfirmation(RenardeCookieFilter cookieFilter, String confirmationCode,
String firstName, String lastName, String userName, String email,
String cookieName) {
Expand Down