testing/java_src/java/com/google/crypto/tink/testing/JwtServiceImpl.java
/** Decodes and verifies a signed, compact JWT. */
Decodes and verifies a signed, compact JWT.
Decodes and verifies a signed compact JWT .
@Override
  public void verifyMacAndDecode(
      JwtVerifyRequest request,
      StreamObserver<JwtVerifyResponse> responseObserver) {
    JwtVerifyResponse response;
    try {
      KeysetHandle keysetHandle =
          CleartextKeysetHandle.read(
              BinaryKeysetReader.withBytes(request.getKeyset().toByteArray()));
      JwtValidator validator = convertProtoValidatorToValidator(request.getValidator());
      JwtMac jwtMac = keysetHandle.getPrimitive(JwtMac.class);
      VerifiedJwt verifiedJwt = jwtMac.verifyMacAndDecode(request.getSignedCompactJwt(), validator);
      JwtToken token = convertVerifiedJwtToJwtToken(verifiedJwt);
      response = JwtVerifyResponse.newBuilder().setVerifiedJwt(token).build();
    } catch (GeneralSecurityException | InvalidProtocolBufferException e) {
      response = JwtVerifyResponse.newBuilder().setErr(e.toString()).build();
    } catch (IOException e) {
      responseObserver.onError(Status.UNKNOWN.withDescription(e.getMessage()).asException());
      return;
    }
    responseObserver.onNext(response);
    responseObserver.onCompleted();
  }
@ Override public void verifyMacAndDecode ( JwtVerifyRequest request , StreamObserver < JwtVerifyResponse > responseObserver ) { JwtVerifyResponse response ; try { KeysetHandle keysetHandle = CleartextKeysetHandle . read ( BinaryKeysetReader . withBytes ( request . getKeyset ( ) . toByteArray ( ) ) ) ; JwtValidator validator = convertProtoValidatorToValidator ( request . getValidator ( ) ) ; JwtMac jwtMac = keysetHandle . getPrimitive ( JwtMac . class ) ; VerifiedJwt verifiedJwt = jwtMac . verifyMacAndDecode ( request . getSignedCompactJwt ( ) , validator ) ; JwtToken token = convertVerifiedJwtToJwtToken ( verifiedJwt ) ; response = JwtVerifyResponse . newBuilder ( ) . setVerifiedJwt ( token ) . build ( ) ; } catch ( GeneralSecurityException | InvalidProtocolBufferException e ) { response = JwtVerifyResponse . newBuilder ( ) . setErr ( e . toString ( ) ) . build ( ) ; } catch ( IOException e ) { responseObserver . onError ( Status . UNKNOWN . withDescription ( e . getMessage ( ) ) . asException ( ) ) ; return ; } responseObserver . onNext ( response ) ; responseObserver . onCompleted ( ) ; }
Decodes and verifies a signed, compact JWT.
Decodes and verifies a signed compact JWT .