我们正在使用带有 Java 的 Stormpath,并且还尝试在同一个应用程序上将表单登录与 REST API 身份验证结合起来。
我已经按照这里的描述设置了stormpath servlet插件https://docs.stormpath.com/java/servlet-plugin/quickstart.html ...这工作得很好。
现在,在同一个应用程序上,我们有 API,我在其中使用 Stormpath 实现了 oAuth 身份验证,请参见此处http://docs.stormpath.com/guides/api-key-management/
Basic Base64(keyId:keySecret)
通过在请求标头和grant_type = client_credentials
正文中发送访问令牌的第一个请求可以正常工作。访问令牌被很好地返回。但是,在返回以下 json 错误消息之前,尝试使用标头验证后续请求Bearer <the-obtained-access-token>
甚至不会命中应用程序...
{
"error": "invalid_client",
"error_description": "access_token is invalid."
}
这很令人困惑,因为我在整个应用程序中都设置了断点,而且我很确定在stormpath 启动并返回此错误之前,API 请求不会到达应用程序中的任何位置。即使stormpath在到达REST接口之前以某种方式拦截了请求,这条消息对我来说也没有任何意义,因为我肯定会使用从第一次调用中获得的有效访问令牌进行后续API调用以获取访问权限-令牌。
我已经不知道为什么会发生这种情况,但我怀疑它可能与stormpath配置有关,尤其是与表单登录/身份验证的Web视图和oAuth身份验证相结合的REST端点。话虽如此,这就是我的stormpath.properties 的样子。希望这可以帮助指出我可能做错的任何事情。
stormpath.application.href=https://api.stormpath.com/v1/applications/[app-id]
stormpath.web.filters.authr=com.app.security.AuthorizationFilter
stormpath.web.request.event.listener = com.app.security.AuthenticationListener
stormpath.web.uris./resources/**=anon
stormpath.web.uris./assets/**=anon
stormpath.web.uris./v1.0/**=anon
stormpath.web.uris./** = authc,authr
stormpath.web.uris./**/**=authc,authr
对此的帮助将不胜感激。