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

Updated webauthn quickstarts #1377

Merged
merged 1 commit into from
Mar 26, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<li><a href="/api/users/me">User API</a></li>
<li><a href="/api/admin">Admin API</a></li>
<li><a href="/q/webauthn/logout">Logout</a></li>
</ul>
</nav>
<div class="container">
<div class="item">
Expand Down Expand Up @@ -86,7 +87,7 @@ <h1>Register</h1>

const loginButton = document.getElementById('login');

loginButton.onclick = () => {
loginButton.addEventListener("click", (e) => {
var userName = document.getElementById('userNameLogin').value;
result.replaceChildren();
webAuthn.login({ name: userName })
Expand All @@ -97,11 +98,11 @@ <h1>Register</h1>
result.append("Login failed: "+err);
});
return false;
};
});

const registerButton = document.getElementById('register');

registerButton.onclick = () => {
registerButton.addEventListener("click", (e) => {
var userName = document.getElementById('userNameRegister').value;
var firstName = document.getElementById('firstName').value;
var lastName = document.getElementById('lastName').value;
Expand All @@ -114,7 +115,7 @@ <h1>Register</h1>
result.append("Registration failed: "+err);
});
return false;
};
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ private void invokeCustomEndpoint(String uri, Filter cookieFilter, Consumer<Requ
.then()
.statusCode(200)
.log().ifValidationFails()
.cookie(WebAuthnController.CHALLENGE_COOKIE, Matchers.is(""))
.cookie(WebAuthnController.USERNAME_COOKIE, Matchers.is(""))
.cookie("quarkus-credential", Matchers.notNullValue());
.cookie(WebAuthnEndpointHelper.getChallengeCookie(), Matchers.is(""))
.cookie(WebAuthnEndpointHelper.getChallengeUsernameCookie(), Matchers.is(""))
.cookie(WebAuthnEndpointHelper.getMainCookie(), Matchers.notNullValue());
}

private void verifyLoggedIn(Filter cookieFilter, String userName, User user) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import org.jboss.resteasy.reactive.RestForm;

import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional;
import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
import io.quarkus.security.webauthn.WebAuthnLoginResponse;
import io.quarkus.security.webauthn.WebAuthnRegisterResponse;
import io.quarkus.security.webauthn.WebAuthnSecurity;
Expand All @@ -25,7 +25,7 @@ public class LoginResource {

@Path("/login")
@POST
@ReactiveTransactional
@WithTransaction
public Uni<Response> login(@RestForm String userName,
@BeanParam WebAuthnLoginResponse webAuthnResponse,
RoutingContext ctx) {
Expand Down Expand Up @@ -63,7 +63,7 @@ public Uni<Response> login(@RestForm String userName,

@Path("/register")
@POST
@ReactiveTransactional
@WithTransaction
public Uni<Response> register(@RestForm String userName,
@BeanParam WebAuthnRegisterResponse webAuthnResponse,
RoutingContext ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import java.util.Set;

import jakarta.enterprise.context.ApplicationScoped;

import io.quarkus.hibernate.reactive.panache.common.runtime.ReactiveTransactional;
import io.quarkus.hibernate.reactive.panache.common.WithTransaction;
import io.quarkus.security.webauthn.WebAuthnUserProvider;
import io.smallrye.mutiny.Uni;
import io.vertx.ext.auth.webauthn.AttestationCertificates;
Expand All @@ -17,21 +16,21 @@
@ApplicationScoped
public class MyWebAuthnSetup implements WebAuthnUserProvider {

@ReactiveTransactional
@WithTransaction
@Override
public Uni<List<Authenticator>> findWebAuthnCredentialsByUserName(String userName) {
return WebAuthnCredential.findByUserName(userName)
.flatMap(MyWebAuthnSetup::toAuthenticators);
}

@ReactiveTransactional
@WithTransaction
@Override
public Uni<List<Authenticator>> findWebAuthnCredentialsByCredID(String credID) {
return WebAuthnCredential.findByCredID(credID)
.flatMap(MyWebAuthnSetup::toAuthenticators);
}

@ReactiveTransactional
@WithTransaction
@Override
public Uni<Void> updateOrStoreWebAuthnCredentials(Authenticator authenticator) {
// leave the scooby user to the manual endpoint, because if we do it here it will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<li><a href="/api/users/me">User API</a></li>
<li><a href="/api/admin">Admin API</a></li>
<li><a href="/q/webauthn/logout">Logout</a></li>
</ul>
</nav>
<div class="container">
<div class="item">
Expand Down Expand Up @@ -86,7 +87,7 @@ <h1>Register</h1>

const loginButton = document.getElementById('login');

loginButton.onclick = () => {
loginButton.addEventListener("click", (e) => {
var userName = document.getElementById('userNameLogin').value;
result.replaceChildren();
webAuthn.login({ name: userName })
Expand All @@ -97,11 +98,11 @@ <h1>Register</h1>
result.append("Login failed: "+err);
});
return false;
};
});

const registerButton = document.getElementById('register');

registerButton.onclick = () => {
registerButton.addEventListener("click", (e) => {
var userName = document.getElementById('userNameRegister').value;
var firstName = document.getElementById('firstName').value;
var lastName = document.getElementById('lastName').value;
Expand All @@ -114,7 +115,7 @@ <h1>Register</h1>
result.append("Registration failed: "+err);
});
return false;
};
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ private void invokeCustomEndpoint(String uri, Filter cookieFilter, Consumer<Requ
.then()
.statusCode(200)
.log().ifValidationFails()
.cookie(WebAuthnController.CHALLENGE_COOKIE, Matchers.is(""))
.cookie(WebAuthnController.USERNAME_COOKIE, Matchers.is(""))
.cookie("quarkus-credential", Matchers.notNullValue());
.cookie(WebAuthnEndpointHelper.getChallengeCookie(), Matchers.is(""))
.cookie(WebAuthnEndpointHelper.getChallengeUsernameCookie(), Matchers.is(""))
.cookie(WebAuthnEndpointHelper.getMainCookie(), Matchers.notNullValue());
}

private void verifyLoggedIn(Filter cookieFilter, String userName, User user) {
Expand Down
Loading