简体   繁体   English

,来自 spring boot 微服务的 web api 调用

[英],web api call from spring boot microservice

I have 2 spring boot microservices hosted on Kubernetes cluster - app A n auth.我在 Kubernetes 集群上托管了 2 个 Spring Boot 微服务 - app A n auth。 app A redirects to auth service getToken api to get a custom jwt token which is a protected API using IBM AppId so before getToken is called, it auto redirects to appId to authenticate user.应用程序 A 重定向到身份验证服务 getToken api 以获取自定义 jwt 令牌,该令牌是使用 IBM AppId 的受保护 API,因此在调用 getToken 之前,它会自动重定向到 appId 以对用户进行身份验证。 After successful auth from appId, custom token is set in cookie and request redirected back to auth A. Now currently my implementation uses cookies.从 appId 成功进行身份验证后,在 cookie 中设置自定义令牌并将请求重定向回身份验证 A。现在我的实现使用 cookie。 app A in filters tries to find the required cookie, if not found, redirects to auth using resp.sendredirect to token api.过滤器中的应用程序 A 尝试找到所需的 cookie,如果未找到,则使用 resp.sendredirect 重定向到 auth 到令牌 api。 app A then is able to find the cookie and gives access to the user to its APIs.然后,应用 A 能够找到 cookie 并授予用户访问其 API 的权限。 Now my issue is, that since i am using resp.sendredirect, i see auth service url in the browser which i dont want, but still trigger web api from app A to get somehow get token even if not in cookie.现在我的问题是,由于我使用的是 resp.sendredirect,我在浏览器中看到了我不想要的身份验证服务 url,但仍然从应用程序 A 触发 web api 以获取令牌,即使不在 cookie 中。

  1. Is there a way to call web api from app A service without using resp.redirect in spring boot like forward or rest template such that the flow is still triggered and my auth service url not shown in browser?有没有办法从应用程序 A 服务调用 web api,而无需在 Spring Boot 中使用 resp.redirect 像 forward 或 rest 模板,这样仍然会触发流并且我的身份验证服务 url 未显示在浏览器中?
  2. Token instead of setting in cookie, can be propagated in any other way such that another app B can also use the same token for auth to simulate SSO scenario for that user without hitting getToken endpoint of auth again ?令牌而不是在 cookie 中设置,可以以任何其他方式传播,以便另一个应用程序 B 也可以使用相同的令牌进行身份验证来模拟该用户的 SSO 场景,而无需再次点击身份验证的 getToken 端点?

Please help as i need to have this SSO enabled based on custom token and also dont want my auth service urls exposed on the browser too.请帮助,因为我需要根据自定义令牌启用此 SSO,并且也不希望我的身份验证服务 URL 也暴露在浏览器上。

Is there a way to call web api from app A service without using redirect?有没有办法在不使用重定向的情况下从应用程序 A 服务调用 web api?

Since you are using OpenID Connect that is based on OAuth2, this is the way it works when the user is not authenticated already.由于您使用的是基于 OAuth2 的 OpenID Connect,因此这是在用户尚未通过身份验证时的工作方式。

Token instead of setting in cookie, can be propagated in any other way such that another app B can also use the same token for auth to simulate SSO scenario for that user without hitting getToken endpoint of auth again ?令牌而不是在 cookie 中设置,可以以任何其他方式传播,以便另一个应用程序 B 也可以使用相同的令牌进行身份验证来模拟该用户的 SSO 场景,而无需再次点击身份验证的 getToken 端点? Please help as i need to have this SSO enabled based on custom token and also dont want my auth service urls exposed on the browser too.请帮助,因为我需要根据自定义令牌启用此 SSO,并且也不希望我的身份验证服务 URL 也暴露在浏览器上。

When using OpenID Connect to authenticate to a service, the service name should be in the Token.使用 OpenID Connect 对服务进行身份验证时,服务名称应在令牌中。 But you may consider all "Deployments" in your cluster as a "single service" (but a distributed microservice architecture), then you can do the Authentication / Token validation in the Gateway on the way into the cluster.但是你可以把你集群中的所有“Deployments”都当成一个“单一的服务”(但是一个分布式微服务架构),然后你就可以在进入集群的途中在Gateway中做Authentication/Token验证。 This is called like Identity Aware Proxy or API Gatways usually have this functionality.这被称为Identity Aware Proxy或 API Gatways 通常具有此功能。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM