简体   繁体   中英

how to get jhipster jwt private key?

I am creating multiple microservice applications with jhipster. I am using UAA server for authentication and tasks related to users. I need to manipulate the JWT that jhipster creates and add a few properties to the payload, but I cannot seem to find how to get jhipster's private key.

jHipster is signing the jwt with rs256 algorithm. I have accessed the jwt and altered the payload, but I cannot sign it with the rs256 algorithm because I don't how to retrieve it. I tried to switch to symmetric algorithms but then I could not verify the token because the verifier works with rs256 algorithm.

ResponseEntity<OAuth2AccessToken> responseEntity = restTemplate.postForEntity(getTokenEndpoint(), entity, OAuth2AccessToken.class);

jhipster is using this code to authenticate and return a token. I am trying to create a new token with:

JwtBuilder token = Jwts.builder()
            .setHeader(headerMap)
            .setClaims((Map<String, Object>) jwtMap.get("payload"))
            .signWith(SignatureAlgorithm.RS256, privateKey);
        String newJwt = token.compact();

but I do not have the private key.

I tried to generate a new private key and work with it but I got Caused by: org.springframework.security.jwt.crypto.sign.InvalidSignatureException: RSA Signature did not match content error. I want to change the jwt payload and add properties to it and use the new token as the access token for jhipster authentication.

thanks in advance

It's in the keystore generated using java keytool.

The command to use is described in comments of application-prod.yml in your generated uaa project.

keytool -genkey -alias uaa -storetype PKCS12 -keyalg RSA -keysize 2048 -keystore keystore.p12 -validity 3650

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM