我正在尝试从Keycloak open-id连接证书端点获取密钥,以允许我验证JWT令牌。用于获取键缝的api工作:
A simple layout design for center two image button
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="loadSomething"
android:layout_margin="20dp"
android:textAlignment="center"
android:text="Click here to load the site"
android:textColor="@color/WhiteSmoke"
android:textSize="16sp"
android:background="@color/Blue"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<ImageButton
android:id="@+id/icon1"
android:onClick="method1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:padding="20dp"
android:adjustViewBounds="true"
android:scaleType = "fitCenter"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:background="@color/WhiteSmoke"
android:src="@mipmap/minus_icon" />
<ImageButton
android:id="@+id/icon2"
android:onClick="method2"
android:layout_width="0dp"
android:layout_weight= "1"
android:layout_height="wrap_content"
android:padding="20dp"
android:adjustViewBounds="true"
android:maxWidth="350dp"
android:maxHeight="350dp"
android:scaleType="fitCenter"
android:background="@color/WhiteSmoke"
android:src="@mipmap/plus_icon"
/>
</LinearLayout>
</RelativeLayout>
但关键在哪里以及如何解码?
GET http://localhost:8080/auth/realms/my-realm/protocol/openid-connect/certs
{
"keys": [
{
"kid": "MfFp7IWWRkFW3Yvhb1eVrtyQQNYqk6BG-6HZFpl_JxI",
"kty": "RSA",
"alg": "RS256",
"use": "sig",
"n": "qDWXUhNtfuHNh0lm3o-oTnP5S8ENpzsyi-dGrjSeewxV6GNiKTW5INJ4hDQ7ZWkUFfJJhfhQWJofqgN9rUBQgbRxXuUvEkrzXQiT9AT_8r-2XLMwRV3eV_t-WRIJhVWsm9CHS2gzbqbNP8HFoB_ZaEt2FYegQSoAFC1EXMioarQbFs7wFNEs1sn1di2xAjoy0rFrqf_UcYFNPlUhu7FiyhRrnoctAuQepV3B9_YQpFVoiUqa_p5THcDMaUIFXZmGXNftf1zlepbscaeoCqtiWTZLQHNuYKG4haFuJE4t19YhAZkPiqnatOUJv5ummc6i6CD69Mm9xAzYyMQUEvJuFw",
"e": "AQAB"
}
]
}
看起来不像base64,我无法弄清楚它是什么?
...如果有人能告诉我如何从该有效载荷中获取公钥,那就太棒了!
答案 0 :(得分:5)
查看https://github.com/keycloak/keycloak/blob/master/core/src/main/java/org/keycloak/jose/jwk/JWKParser.java它返回密钥的接缝是使用以下符号进行pem编码的:
modulus
exponent
查看提到的java类以获取java中的公钥或https://github.com/tracker1/node-rsa-pem-from-mod-exp以获取javascript中的公钥。
答案 1 :(得分:0)
一个或多个键的类型为JSON Web Key (JWK)。受支持的库列表在OpenID web page上。我正在使用jose.4.j从Keycloak检索密钥。