我正在努力构建一个Micronaut应用程序,该应用程序通过Keycloak实现OpenID身份验证。
为简单起见,我采取了Micronaut Okta示例(https://guides.micronaut.io/micronaut-oauth2-okta/guide/index.html),并更改了application.yml中的条目以寻址我们的Keycloak服务器,并修改了home.html中的“ / oauth / login / okta”链接到“ / oauth / login / keycloak”,并在logback.xml中添加了io.micronaut.security记录器。
身份验证似乎在某种程度上起作用(出现Keycloak登录,并且登录浏览器返回Micronaut站点后),但是Micronaut站点似乎无法“识别”它。
有人知道这是怎么回事吗?
application.yml:
micronaut:
application:
name: examples
server:
port: 8080
cors:
enabled: true
security:
enabled: true # <1>
oauth2:
enabled: true
clients:
keycloak:
client-secret: 'd3e283af-3a97-4c1f-b76e-ed39d3c28ca2'
client-id: 'mykctest-admin'
openid:
issuer: 'https://login.mykeycloak.org/auth/realms/mykctest'
token:
jwt:
enabled: true # <6>
cookie:
enabled: true # <7>
signatures:
secret:
generator:
secret: pleaseChangeThisSecretForANewOne
endpoints:
logout:
enabled: true # <8>
get-allowed: true # <9>
部分日志输出:
> ... 16:14:22.224 [nioEventLoopGroup-1-30] TRACE
> i.m.s.o.e.a.r.DefaultOpenIdAuthorizationResponseHandler - Token
> validation succeeded. Creating a user details 16:14:22.225
> [nioEventLoopGroup-1-30] TRACE i.m.s.o.r.DefaultOauthController -
> Authentication succeeded. User [6a316b0d-4d1e-4a8b-a06b-96e6b6363229]
> is now logged in 16:14:22.225 [nioEventLoopGroup-1-30] DEBUG
> i.m.s.t.j.g.c.JWTClaimsSetGenerator - Setting expiration to 3600
> 16:14:22.226 [nioEventLoopGroup-1-30] DEBUG
> i.m.s.t.j.g.c.JWTClaimsSetGenerator - Generated claim set: { <contains
> usernames and access tokens...> } 16:14:22.229
> [nioEventLoopGroup-1-30] DEBUG i.m.s.t.j.g.c.JWTClaimsSetGenerator -
> Generated claim set: { <contains usernames and access tokens...> }
> 16:14:22.245 [pool-2-thread-2] DEBUG
> i.m.s.t.reader.HttpHeaderTokenReader - Looking for bearer token in
> Authorization header 16:14:22.245 [pool-2-thread-2] DEBUG
> i.m.s.t.reader.HttpHeaderTokenReader - Looking for bearer token in
> Authorization header 16:14:22.245 [pool-2-thread-2] DEBUG
> i.m.s.t.reader.DefaultTokenResolver - Request GET, /, no token found.
> 16:14:22.245 [pool-2-thread-2] DEBUG
> i.m.security.filters.SecurityFilter - No Authentication fetched for
> request. GET /. 16:14:22.245 [pool-2-thread-2] DEBUG
> i.m.security.filters.SecurityFilter - Authorized request GET /. The
> rule provider io.micronaut.security.rules.SecuredAnnotationRule
> authorized the request. ...
答案 0 :(得分:0)
这可能是因为Cookie太大。 Keycloak似乎比存储在JWT中的普通令牌生成的令牌更大。在Oauth的最新快照中,除非进行配置,否则这些参数不会存储在JWT中。请尝试使用最新的快照