简体   繁体   English

springboot 获取令牌以调用另一个服务

[英]springboot get token to call another service

I want to make GET request from SpringBoot.我想从 SpringBoot 发出 GET 请求。 Can I use org.keycloak.admin.client.Keycloak only to get and refresh token to access an API in another microservice?我可以仅使用org.keycloak.admin.client.Keycloak来获取和刷新令牌以访问另一个微服务中的 API 吗? I thouth it is only for manage, for adding roles etc. Not for authorization.我虽然它仅用于管理,用于添加角色等。不用于授权。

        keycloak = KeycloakBuilder
            .builder()
            .serverUrl(serverUrl)
            .grantType(OAuth2Constants.PASSWORD)
            .realm(realm)
            .clientId(clientId)
            .username(userName)
            .password(pass)
            .build();

    AccessTokenResponse accessToken = keycloak.tokenManager().getAccessToken();

It works but still I have bad feeling about using admin client here.它有效,但我仍然对在这里使用管理客户端有不好的感觉。 For the Angular client, this is a similar way, but not from the admin package.对于 Angular 客户端,这是类似的方式,但不是来自管理员 package。

Was this action started by an user?此操作是否由用户启动? Usually you want to use the same token that came from your front-end and pass it along on your request, this way you can trace your request all the way back to who started it.通常,您希望使用来自前端的相同令牌并将其传递给您的请求,这样您就可以将您的请求一直追溯到发起者。

Using a token for your service means it can acess other services without being prompted by a human, maybe you want this, but typically you don't.为您的服务使用令牌意味着它可以在没有人提示的情况下访问其他服务,也许您想要这个,但通常您不需要。

If you still want to get a token for your client you can use service accounts as described here:如果您仍想为您的客户获取令牌,您可以使用此处所述的服务帐户:

https://github.com/keycloak/keycloak-documentation/blob/master/server_admin/topics/clients/oidc/service-accounts.adoc https://github.com/keycloak/keycloak-documentation/blob/master/server_admin/topics/clients/oidc/service-accounts.adoc

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Springboot微服务api中,如何使用AMQP队列调用另一个服务器,如何从另一个服务队列获取响应,发送响应 - In Springboot microservices api, how to call a another server using AMQP queue, get response from the another service queue, send the response Spring Boot从请求中获取承载令牌并调用另一个微服务 - spring boot get bearer token from request and call another microservice 在api调用之前,springboot oauth访问令牌验证以及用户详细信息 - springboot oauth access token validation with user details before api call springboot中如何在另一个api中调用另一个post mapping api - How to call another post mapping api in another api in springboot 在SpringBoot客户端中使用WebServiceTemplate进行SOAP Web服务调用 - SOAP web service call using WebServiceTemplate in SpringBoot client 如何通过 SpringBoot 从 Keycloak 获取访问令牌? - How to get Access Token from Keycloak over SpringBoot? 如何在Springboot中使用Autentication Basic作为标头发送访问令牌 - How to get the access token sent in as header with Autentication Basic in Springboot 如何在外部站点的SpringBoot中获取令牌:Thymeleaf错误 - How to get a Token in SpringBoot form external Site: Thymeleaf Error 在 SpringBoot 应用程序中获取从 JSON 生成的访问令牌 - Get Access token genertaed from JSON in SpringBoot Application Springboot:自动将从swagger UI捕获的JWT token传递给下游(Service to service)API调用 - Springboot: Pass the JWT token captured from swagger UI to the downstream(Service to service) API calls automatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM