英文:
How to configure RSAKey.Builder to produce simple result without null values
问题
{
"keys": [
{
"kty": "RSA",
"e": "AQAB",
"use": "sig",
"kid": "65b413b1-94c8-48ce-a79a-ba4978460205",
"alg": "RS256",
"n": "123456789-987654321...etc."
}
]
}
英文:
I have a code like this:
// get keyPair...
final JWK jwk = new RSAKey.Builder((RSAPublicKey) keyPair.getPublic())
.privateKey((RSAPrivateKey) keyPair.getPrivate())
.keyUse(KeyUse.SIGNATURE)
.algorithm(JWSAlgorithm.RS256)
.keyID("1")
.build();
return new JWKSet(jwk.toPublicJWK());
It produces result like this:
keys: [
{
keyStore: null,
private: false,
modulus: { },
privateExponent: null,
publicExponent: { },
secondPrimeFactor: null,
firstPrimeFactor: null,
secondFactorCRTExponent: null,
firstCRTCoefficient: null,
firstFactorCRTExponent: null,
requiredParams: {
e: "AQAB",
kty: "RSA",
n: "123456789-987654321...etc."
},
otherPrimes: [ ],
algorithm: {
name: "RS256",
requirement: null
},
keyType: {
value: "RSA",
requirement: "REQUIRED"
},
x509CertThumbprint: null,
x509CertSHA256Thumbprint: null,
parsedX509CertChain: null,
keyID: "1",
keyUse: {
value: "sig"
},
keyOperations: null,
x509CertURL: null,
x509CertChain: null
}
],
additionalMembers: { }
}
I would expect something simpler, like this:
{
"keys": [
{
"kty": "RSA",
"e": "AQAB",
"use": "sig",
"kid": "65b413b1-94c8-48ce-a79a-ba4978460205",
"alg": "RS256",
"n": "123456789-987654321...etc."
}
]
}
What should I do to produce this format instead of the former one?
答案1
得分: 0
抱歉,我的端点设置错误。
应该是:
@GetMapping
public Map<String, Object> getJwks() {
return jwksService.getJwkSet().toJSONObject(true);
}
英文:
My bad, my endpoint was wrong.
Instead of:
@GetMapping
public ResponseEntity<JWKSet> getJwks() {
return ResponseEntity
.status(HttpStatus.OK)
.body(jwksService.getJwkSet());
}
there is suppose to be:
@GetMapping
public Map<String, Object> getJwks() {
return jwksService.getJwkSet().toJSONObject(true);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论