OAuth 2.0,应用程序服务器 - WebSphere Liberty - 10 分钟后不清楚重定向到 Microsoft
OAuth 2.0, app server - WebSphere Liberty - unclear redirect to microsoft after 10 minutes
我有简单的 REST 服务,集成了 Swagger UI,应用服务器 - WepSphere Liberty,
我已经使用 openidConnectClient 功能成功实现了 OAuth 2.0 授权的授权代码流程。工作正常,用户正在登录 Microsoft 站点并成功重定向到我的 Web 应用程序。
问题是 10 分钟后 当我尝试通过 Swagger UI 向服务器执行简单请求时,我得到一个错误
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" language="javascript">var loc=window.location.href;document.cookie="WASReqURLOidcn377114111="+loc+"; path=/;"</script><script type="text/javascript" language="javascript">window.location.replace("https://login.microsoftonline.com/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxx/oauth2/v2.0/authorize?response_type=code&client_id=.......</script>
<title>Redirect To OP</title>
</head>
<body></body>
</html>
server.xml:
<authFilter id="app-filter">
<requestHeader id="excludeBearer" name="Authorization" value="Bearer" matchType="notContain"/>
<requestHeader id="excludeBasic" name="Authorization" value="Basic" matchType="notContain"/>
</authFilter>
<openidConnectClient id="app-oidc"
authFilterRef="app-filter"
useSystemPropertiesForHttpClientConnections="true"
jwkEndpointUrl="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/discovery/v2.0/keys"
issuerIdentifier="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/v2.0"
audiences="<clientId of our application>"
userIdentityToCreateSubject="<our custom claim>"
mapIdentityToRegistryUser="false"
inboundPropagation="none"
signatureAlgorithm="RS256"
tokenReuse="true"
clientId="..."
clientSecret="..."
authorizationEndpointUrl="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/v2.0/authorize"
tokenEndpointUrl="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/v2.0/token"
responseType="code"
groupIdentifier="roles"
sslRef="defaultSSLConfig">
</openidConnectClient>
似乎发生了什么事,它再次尝试授权
这对我来说很奇怪,默认的 oauth 令牌生命周期是 1h30m,我什至不知道到底发生了什么
有人可以帮我解决这个问题吗?
我还不能发表评论,但我有一些 questions/comments。
- 具体是什么错误?
- 微软授权后,你应该
获得授权令牌,但您是否请求访问令牌?
- 在这 10 分钟之前请求是否有效
- 此外,请仔细检查您的 URL 请求,看看查询中是否有任何错误。
我认为这是由于 Liberty 缓存过期,缓存的主题已被删除。有多种方法可以解决这个问题,以下是我比较喜欢的方法。
1:添加 <authnCache timeout="1800s" />
将缓存超时从默认的 10 分钟更改为 30 分钟。
(可选)2:将 disableLtpaCookie="true" 添加到 openidConnectClient 配置元素,它将使用 id_token 生命周期作为安全会话时间。
3:在openidConnectClient配置元素中添加isClientSideRedirectSupported="false",支持javascript,直接将浏览器重定向到IdP进行登录。
@春龙
能否提供更多有关缓存超时的信息?这是关于 authCache
的吗? (IBM docs)
P.S。关于 isClientRedirectSupported="false" 的一个小提示:如果使用此功能,openidConnectClientFeature 提供的 servlet 将不会在转到应用程序时发回 302。取而代之的是——servlet 将以状态 200 和 html 响应自提交表单。从技术上讲——它不是重定向,但结果是一样的:浏览器将显示 IdP 的登录页面。
(遗憾的是,没有足够的声誉来发表评论)
我有简单的 REST 服务,集成了 Swagger UI,应用服务器 - WepSphere Liberty, 我已经使用 openidConnectClient 功能成功实现了 OAuth 2.0 授权的授权代码流程。工作正常,用户正在登录 Microsoft 站点并成功重定向到我的 Web 应用程序。 问题是 10 分钟后 当我尝试通过 Swagger UI 向服务器执行简单请求时,我得到一个错误
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" language="javascript">var loc=window.location.href;document.cookie="WASReqURLOidcn377114111="+loc+"; path=/;"</script><script type="text/javascript" language="javascript">window.location.replace("https://login.microsoftonline.com/xxxxxxxxx-xxxx-xxxx-xxxx-xxxxx/oauth2/v2.0/authorize?response_type=code&client_id=.......</script>
<title>Redirect To OP</title>
</head>
<body></body>
</html>
server.xml:
<authFilter id="app-filter">
<requestHeader id="excludeBearer" name="Authorization" value="Bearer" matchType="notContain"/>
<requestHeader id="excludeBasic" name="Authorization" value="Basic" matchType="notContain"/>
</authFilter>
<openidConnectClient id="app-oidc"
authFilterRef="app-filter"
useSystemPropertiesForHttpClientConnections="true"
jwkEndpointUrl="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/discovery/v2.0/keys"
issuerIdentifier="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/v2.0"
audiences="<clientId of our application>"
userIdentityToCreateSubject="<our custom claim>"
mapIdentityToRegistryUser="false"
inboundPropagation="none"
signatureAlgorithm="RS256"
tokenReuse="true"
clientId="..."
clientSecret="..."
authorizationEndpointUrl="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/v2.0/authorize"
tokenEndpointUrl="https://login.microsoftonline.com/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/oauth2/v2.0/token"
responseType="code"
groupIdentifier="roles"
sslRef="defaultSSLConfig">
</openidConnectClient>
似乎发生了什么事,它再次尝试授权 这对我来说很奇怪,默认的 oauth 令牌生命周期是 1h30m,我什至不知道到底发生了什么
有人可以帮我解决这个问题吗?
我还不能发表评论,但我有一些 questions/comments。
- 具体是什么错误?
- 微软授权后,你应该 获得授权令牌,但您是否请求访问令牌?
- 在这 10 分钟之前请求是否有效
- 此外,请仔细检查您的 URL 请求,看看查询中是否有任何错误。
我认为这是由于 Liberty 缓存过期,缓存的主题已被删除。有多种方法可以解决这个问题,以下是我比较喜欢的方法。
1:添加 <authnCache timeout="1800s" />
将缓存超时从默认的 10 分钟更改为 30 分钟。
(可选)2:将 disableLtpaCookie="true" 添加到 openidConnectClient 配置元素,它将使用 id_token 生命周期作为安全会话时间。
3:在openidConnectClient配置元素中添加isClientSideRedirectSupported="false",支持javascript,直接将浏览器重定向到IdP进行登录。
@春龙
能否提供更多有关缓存超时的信息?这是关于 authCache
的吗? (IBM docs)
P.S。关于 isClientRedirectSupported="false" 的一个小提示:如果使用此功能,openidConnectClientFeature 提供的 servlet 将不会在转到应用程序时发回 302。取而代之的是——servlet 将以状态 200 和 html 响应自提交表单。从技术上讲——它不是重定向,但结果是一样的:浏览器将显示 IdP 的登录页面。
(遗憾的是,没有足够的声誉来发表评论)