How to access a Jakarta EE Rest Application secured by Keycloak in Java? - Stack Overflow

I have a Jakarta EE Web Application running on Wildfly and secured by Keycloak. For this purpose I use

I have a Jakarta EE Web Application running on Wildfly and secured by Keycloak. For this purpose I use the default Wildfly OIDC support from Elytron to protect my application. All works fine so far. I can access my application via Browser and I am redirected to the Keycloak server for login. After that I can access all my resources in my Web application.

My question is the following: How can I do the same in a Backend Java Service. I need to poll data from a backend service out form my application via the rest API.

I figured out that I can get an Access Token with the following Curl example:

curl -d 'client_id=my-clientid' -d 'username=anna' -d 'password=123' \
-d 'grant_type=password' -d 'client_secret=MY-SECRET' \
''

My assumption was, that I only need to add the Bearer Token into the header of a new request:

curl -X GET "/" \
  -H "Authorization: Bearer eyJhbGciOiJ.................."

But this second request against my Jakarta EE Web Application did not work. I will be redirected (302) again to the Keycloak Loign Page.

How is the correct way to access a Jakarta EE Web App with a Keycloak Token?

I guess this is a typical OpenID Connect workflow?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744803458a4594630.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信