Giter Site home page Giter Site logo

jackjhy / java-u2flib-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yubico/java-u2flib-server

0.0 1.0 0.0 1.27 MB

Java server-side library for U2F

Home Page: https://developers.yubico.com/java-u2flib-server

License: Other

Java 93.70% HTML 0.28% JavaScript 5.09% FreeMarker 0.94%

java-u2flib-server's Introduction

java-u2flib-server

Server-side U2F library for Java. Provides functionality for registering U2F devices and authenticate with said devices.

Dependency

 <dependency>
   <groupId>com.yubico</groupId>
   <artifactId>u2flib-server-core</artifactId>
   <version>0.15.0</version>
 </dependency>

Example Usage

Note
Make sure that you have read Using a U2F library before continuing.
@GET
public View startAuthentication(String username) throws NoEligableDevicesException {

    // Generate a challenge for each U2F device that this user has registered
    AuthenticateRequestData requestData
        = u2f.startAuthentication(SERVER_ADDRESS, getRegistrations(username));

    // Store the challenges for future reference
    requestStorage.put(requestData.getRequestId(), requestData.toJson());

    // Return an HTML page containing the challenges
    return new AuthenticationView(requestData.toJson(), username);
}

@POST
public String finishAuthentication(AuthenticateResponse response, String username) throws
        DeviceCompromisedException {

    // Get the challenges that we stored when starting the authentication
    AuthenticateRequestData authenticateRequest
        = requestStorage.remove(authenticateResponse.getRequestId());

    // Verify the that the given response is valid for one of the registered devices
    u2f.finishAuthentication(authenticateRequest,
                             authenticateResponse,
                             getRegistrations(username));

    return "Successfully authenticated!";
}

In the above example getRegistrations() returns the U2F devices currently associated with a given user. This is most likely stored in a database. See u2flib-server-demo for a complete demo server (including registration and storage of U2F devices).

JavaDoc

JavaDoc can be found at developers.yubico.com/java-u2flib-server.

Attestation

The attestation module (u2flib-server-attestation) enables you to restrict registrations to certain U2F devices (e.g. devices made by a specific vendor). It can also provide metadata for devices.

Serialization

All relevant classes implements Serializable, so instead of using toJson(), you can use Java’s built in serialization mechanism. Internally the classes use Jackson to serialize to and from JSON, and the ObjectMapper from Jackson can be used.

java-u2flib-server's People

Contributors

minisu avatar dainnilsson avatar

Watchers

tiger avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.