- Notifications
You must be signed in to change notification settings - Fork87
A portable Java library for WebAuthn(Passkeys) server side verification
License
webauthn4j/webauthn4j
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A portable Java library for WebAuthn(Passkeys) server side verification
All mandatory test cases and optional Android Key attestation test cases ofFIDO2 Test Tools provided by FIDO Allianceare passed.
All attestation statement formats are supported.
- Packed attestation
- FIDO U2F attestation
- Android Key attestation
- Android SafetyNet attestation
- TPM attestation
- Apple Anonymous attestation
- None attestation
- Apple App Attest attestation
Although WebAuthn4J is written in Java, public members are marked byNotNull orNullable annotationto declare nullability explicitly.
- Keycloak andRed Hat build of Keycloak
- Spring Security
spring-security-webmodule provides passkeys support- maintained by Spring Security project
- WebAuthn4J Spring Security
- extension for spring security to add webauthn(passkey) support
- maintained by WebAuthn4J project
- Eclipse Vert.x Auth
- OpenAM
- OpenUnison
You can find out more details from thereference.
If you are using Maven, just add the webauthn4j as a dependency:
<properties> ...<!-- Use the latest version whenever possible.--> <webauthn4j.version>0.30.1.RELEASE</webauthn4j.version> ...</properties><dependencies> ... <dependency> <groupId>com.webauthn4j</groupId> <artifactId>webauthn4j-core</artifactId> <version>${webauthn4j.version}</version> </dependency> ...</dependencies>
WebAuthn4J uses a Gradle based build system.In the instructions below,gradlew is invoked from the root of the source tree and serves as a cross-platform,self-contained bootstrap mechanism for the build.
Java17 or later is required to build WebAuthn4J.To use WebAuthn4J library, JDK11 is OK if you don't need EdDSA support.
git clone https://github.com/webauthn4j/webauthn4j./gradlew buildParse and Validation on WebAuthn registration
If your would like to verify Apple App Attest, please see the reference.
StringregistrationResponseJSON ="<registrationResponseJSON>";/* set registrationResponseJSON received from frontend */RegistrationDataregistrationData;try {registrationData =webAuthnManager.parseRegistrationResponseJSON(registrationResponseJSON);}catch (DataConversionExceptione) {// If you would like to handle WebAuthn data structure parse error, please catch DataConversionExceptionthrowe;}// Server propertiesOriginorigin =null/* set origin */;StringrpId =null/* set rpId */;Challengechallenge =null/* set challenge */;byte[]tokenBindingId =null/* set tokenBindingId */;ServerPropertyserverProperty =newServerProperty(origin,rpId,challenge,tokenBindingId);// expectationsList<PublicKeyCredentialParameters>pubKeyCredParams =null;booleanuserVerificationRequired =false;booleanuserPresenceRequired =true;RegistrationParametersregistrationParameters =newRegistrationParameters(serverProperty,pubKeyCredParams,userVerificationRequired,userPresenceRequired);try {webAuthnManager.verify(registrationData,registrationParameters);}catch (VerificationExceptione) {// If you would like to handle WebAuthn data verification error, please catch VerificationExceptionthrowe;}// please persist CredentialRecord object, which will be used in the authentication process.CredentialRecordcredentialRecord =newCredentialRecordImpl(// You may create your own CredentialRecord implementation to save friendly authenticator nameregistrationData.getAttestationObject(),registrationData.getCollectedClientData(),registrationData.getClientExtensions(),registrationData.getTransports() );save(credentialRecord);// please persist credentialRecord in your manner
Parse and Validation on authentication
StringauthenticationResponseJSON ="<authenticationResponseJSON>";/* set authenticationResponseJSON received from frontend */AuthenticationDataauthenticationData;try {authenticationData =webAuthnManager.parseAuthenticationResponseJSON(authenticationResponseJSON);}catch (DataConversionExceptione) {// If you would like to handle WebAuthn data structure parse error, please catch DataConversionExceptionthrowe;}// Server propertiesOriginorigin =null/* set origin */;StringrpId =null/* set rpId */;Challengechallenge =null/* set challenge */;byte[]tokenBindingId =null/* set tokenBindingId */;ServerPropertyserverProperty =newServerProperty(origin,rpId,challenge,tokenBindingId);// expectationsList<byte[]>allowCredentials =null;booleanuserVerificationRequired =true;booleanuserPresenceRequired =true;CredentialRecordcredentialRecord =load(authenticationData.getCredentialId());// please load authenticator object persisted in the registration process in your mannerAuthenticationParametersauthenticationParameters =newAuthenticationParameters(serverProperty,credentialRecord,allowCredentials,userVerificationRequired,userPresenceRequired );try {webAuthnManager.verify(authenticationData,authenticationParameters);}catch (VerificationExceptione) {// If you would like to handle WebAuthn data validation error, please catch ValidationExceptionthrowe;}// please update the counter of the authenticator recordupdateCounter(authenticationData.getCredentialId(),authenticationData.getAuthenticatorData().getSignCount());
WebAuthn4J Spring Security is built on the top of WebAuthn4J, and its sample application demonstrates WebAuthn4J feature well.Please seeWebAuthn4J Spring Security sample application.
WebAuthn4J is Open Source software released under theApache 2.0 license.
Interested in helping out with WebAuthn4J? Great! Your participation in the community is much appreciated!Please feel free to open issues and send pull-requests.
About
A portable Java library for WebAuthn(Passkeys) server side verification
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
