负载 JWT 结构
Payload JWT structure
我正在尝试设置我的 JWT 令牌,但它与往常一样具有不同的有效负载结构,
我该如何设置这种负载结构?
{
"https://daml.com/ledger-api": {
"ledgerId": "sandbox",
"applicationId": "foobar",
"actAs": ["Alice"]
}
}
我只能这样设置:
{
"sub": "https://daml.com/ledger-api",
"ledgerId": "sandbox",
"applicationId": "foobar",
"actAs": "[Alice]"
}
我的java代码:
void getJWT() throws UnsupportedEncodingException {
Claims claims = Jwts.claims().setSubject("https://daml.com/ledger-api");
claims.put("ledgerId","sandbox");
claims.put("applicationId", "foobar");
claims.put("actAs", "[Alice]");
String jwtToken = Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS256, "sYn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E=".getBytes("UTF-8"))
.setHeaderParam("typ", Header.JWT_TYPE)
.compact();
System.out.println("The generated jwt token is as follows:" + jwtToken);
}
How can i set this kind of payload structure?
{
"https://daml.com/ledger-api": {
"ledgerId": "sandbox",
"applicationId": "foobar",
"actAs": ["Alice"]
}
}
您可以通过如下所述修改代码轻松实现上述有效负载结构。
void getJWT() throws UnsupportedEncodingException {
Map<String, String> claims = new HashMap<String, String>();
claims.put("ledgerId", "sandbox");
claims.put("applicationId", "foobar");
claims.put("actAs", "[Alice]");
Map<String, Object> claimsMap = new HashMap<String, Object>();
claimsMap.put("https://daml.com/ledger-api", claims);
String jwtToken = Jwts.builder()
.setClaims(claimsMap)
.signWith(SignatureAlgorithm.HS256, "sYn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E=".getBytes("UTF-8"))
.setHeaderParam("typ", Header.JWT_TYPE)
.compact();
System.out.println("The generated jwt token is as follows:" + jwtToken);
}
我正在尝试设置我的 JWT 令牌,但它与往常一样具有不同的有效负载结构, 我该如何设置这种负载结构?
{
"https://daml.com/ledger-api": {
"ledgerId": "sandbox",
"applicationId": "foobar",
"actAs": ["Alice"]
}
}
我只能这样设置:
{
"sub": "https://daml.com/ledger-api",
"ledgerId": "sandbox",
"applicationId": "foobar",
"actAs": "[Alice]"
}
我的java代码:
void getJWT() throws UnsupportedEncodingException {
Claims claims = Jwts.claims().setSubject("https://daml.com/ledger-api");
claims.put("ledgerId","sandbox");
claims.put("applicationId", "foobar");
claims.put("actAs", "[Alice]");
String jwtToken = Jwts.builder()
.setClaims(claims)
.signWith(SignatureAlgorithm.HS256, "sYn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E=".getBytes("UTF-8"))
.setHeaderParam("typ", Header.JWT_TYPE)
.compact();
System.out.println("The generated jwt token is as follows:" + jwtToken);
}
How can i set this kind of payload structure?
{ "https://daml.com/ledger-api": { "ledgerId": "sandbox", "applicationId": "foobar", "actAs": ["Alice"] } }
您可以通过如下所述修改代码轻松实现上述有效负载结构。
void getJWT() throws UnsupportedEncodingException {
Map<String, String> claims = new HashMap<String, String>();
claims.put("ledgerId", "sandbox");
claims.put("applicationId", "foobar");
claims.put("actAs", "[Alice]");
Map<String, Object> claimsMap = new HashMap<String, Object>();
claimsMap.put("https://daml.com/ledger-api", claims);
String jwtToken = Jwts.builder()
.setClaims(claimsMap)
.signWith(SignatureAlgorithm.HS256, "sYn2kjibddFAWtnPJ2AFlL8WXmohJMCvigQggaEypa5E=".getBytes("UTF-8"))
.setHeaderParam("typ", Header.JWT_TYPE)
.compact();
System.out.println("The generated jwt token is as follows:" + jwtToken);
}