通过Spring Social传递额外的查询/表单参数 [英] Passing extra query/form parameters through spring social
问题描述
我正在使用JHipster生成的Spring Social和Spring Security构建一个单页面应用程序。
我正在尝试在某个社交身份验证提供商对用户进行身份验证后捕获原始查询参数。
示例:
调用/signin/someprovider?show=someEntityId并在身份验证成功后将用户重定向到/Sign Up/后,我需要一种方法来获取"某个实体ID"。
我认为不同的http调用会使传递/存储参数变得困难。 有没有一些我可以使用/重用的Spring内置功能,或者如何解决这个问题?
更新
请求线程如下所示:
(1)浏览器->http://localhost:9060/signin/authenticationProvider?show=**someEntityId**
<;-重定向至https://authenticationProvider... &state=SomeState
(2)浏览器->https://authenticationProvider
<;-重定向至http://localhost:9060/signin/google?state=SomeState&code=SomeCode
(3)浏览器->http://localhost:9060/signin/authenticationProvider?state=SomeState&code=SomeCode
<;-重定向至http://localhost:9060/social/signup
(4)浏览器->http://localhost:9060/social/signup
最终结果为
@GetMapping("/signup")
public RedirectView signUp(WebRequest webRequest, @CookieValue(name = "NG_TRANSLATE_LANG_KEY", required = false, defaultValue = Constants.DEFAULT_LANGUAGE) String langKey) {
try {
Connection<?> connection = providerSignInUtils.getConnectionFromSession(webRequest);
socialService.createSocialUser(connection, langKey.replace(""", ""));
此时,它希望使用原始参数调用一个函数某一实体ID。
根据google oauth2 redirect_uri with several parameters,为了继续存在,应在OAuth2请求的状态参数中编码?show=某实体ID参数 从(1)到(3)。在(3)中,状态参数必须被添加到重定向URI,使得原始参数可以在(4)中被解码。
看起来需要做很多工作,还是我错过了什么?如果有一种方法可以有一个会话变量,我可以在其中存储(1)中的参数,并在(4)中再次获取它们,那就太好了。
推荐答案
由于1.1.3版的Spring Social自行创建状态参数并将其用作csrf令牌,请参阅https://pivotal.io/security/cve-2015-5258-因此您可以(而不应该)在状态参数中编码其他参数。
相反,如果提供商签名启用了ProviderSignInController
,则ProviderSignInInterceptor
可用于在会话(在preSignIn(...)
和postSignIn(...)
中)中间存储此类参数。
我猜如果使用SocialAuthenticationFilter
,也会有类似的方法。
这篇关于通过Spring Social传递额外的查询/表单参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!