解析JWT令牌有效载荷数据以在android/java中获得特定值 [英] Parse JWT token payload data to get certain value in android/java
问题描述
我刚被介绍给JWT,想知道如何使用密钥解析有效载荷数据以从中获取特定值.
以下JWT令牌中的示例eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRaWHJEHJHZHYHJ7HZHYHW7B7E7BWH7HYHW7B7E7B7E7B7E7B7EJ7E7B7E7B7E7E7B
在jwt.io中解码时,有效载荷数据包含以下对象
{
"sub" : "1234567890"
"name" : "John Doe"
"admin" : "true"
}
我希望能够解析该对象以从上面的JWT令牌中获取name的值,在这种情况下为John Doe.
我已经阅读了 Android JWT在签名时解析有效负载/声明
但是我想知道是否存在使用某些库在android中进行此操作的有效方法.任何帮助,将不胜感激.
我通常通过解析字符串并从base64对其进行解码,然后将字符串转换为JSONObject并解析JSONObject以获得所需的值,从而解决了该问题.I just got introduced to the JWT and wanted to know how to parse the payload data to get a certain value from it using the key.
Example in the following JWT token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWV9.TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ
The payload data contains the following object when decoded in jwt.io
{
"sub" : "1234567890"
"name" : "John Doe"
"admin" : "true"
}
I want to be able to parse this object to get the value of name which in this case is John Doe from the above JWT token.
I have already read this Android JWT parsing payload/claims when signed
But i wanted to know if there is efficient way to do this in android using some library. Any help would be appreciated.
I solved it, by normally parsing the string and decoding it from base64 and then casting the string to JSONObject and parsing the JSONObject to get the required value.
这篇关于解析JWT令牌有效载荷数据以在android/java中获得特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!