Class DPoPProofVerifier

java.lang.Object
com.codename1.backend.security.oauth2.jwt.DPoPProofVerifier

public final class DPoPProofVerifier extends Object

Checks a DPoP proof (RFC 9449): a JWT the client signs, per request, with the private half of the key its tokens are bound to. Both the authorization server's token endpoint and a resource server use it.

A proof is accepted when its header says typ dpop+jwt, names an asymmetric algorithm and carries a public jwk the signature verifies with; its htm and htu are the request's method and URI; its iat is within a minute of now; its jti has not been seen before; and, at a resource server, its ath is the hash of the access token sent with it.

  • Constructor Details

    • DPoPProofVerifier

      public DPoPProofVerifier(Clock clock, DPoPProofVerifier.ReplayCache replay)
      Parameters:
      replay - where used proofs are remembered; null for a bounded in-memory cache, which is right for one process and wrong for several behind a load balancer
  • Method Details

    • verify

      public String verify(String proof, String method, String uri, String accessToken)
      Verifies proof and answers the thumbprint of the key it was signed with (its jkt).
      Parameters:
      method - the request's method
      uri - the request's URI, without its query or fragment
      accessToken - the token sent with the proof, which ath must hash; null at the token endpoint
      Throws:
      BadJwtException - when the proof is not acceptable
    • check

      public DPoPProofVerifier.Proof check(String proof, String method, String uri, String accessToken)
      Verifies proof as verify(String, String, String, String) does but records nothing: the caller passes the answer to firstUse(DPoPProofVerifier.Proof) once the request it came with has otherwise succeeded. An endpoint that anyone can reach with a proof of their own key (a token request from a public client) would otherwise let a flood of junk requests fill the replay cache, which refuses every proof once it is full of live ones.
      Throws:
      BadJwtException - when the proof is not acceptable
    • firstUse

      public boolean firstUse(DPoPProofVerifier.Proof proof)
      Records a proof check(String, String, String, String) accepted.
      Returns:
      false when the proof was used before