is there a way to get Socially signed in user from Servlet request using Stormpath?

偶尔善良 提交于 2019-12-25 10:00:50

问题


Using stormpath web login, once a User has been authenticated, the currently logged in user Account is available on subsequent requests and can be retrieved by doing the following (e.g from within a Servlet) ;

Account account = AccountResolver.INSTANCE.getAccount(request);

where request is HttpServletRequest

Now, what i need to know is, why is it not possible to do the same thing for a socially signed in user (i.e a user that signs in with google, facebook, linked-in)???

I know that on sign-up/sign-in, the Account can be retrieved by doing the following;

String applicationHref = appHref;
String code = request.getParameter("code");

Application application = client.getResource(appHref, Application.class);
ProviderAccountRequest request = Providers.GOOGLE.account()
            .setCode(code)
            .build();

ProviderAccountResult result = application.getAccount(request);
Account account = result.getAccount();

But afterwards, doing Account account = AccountResolver.INSTANCE.getAccount(request); always returns null.

Now this is a problem because code is only available on sign in and not for subsequent requests hence using the snippet above is not possible. Besides, it seems like too much work for everytime the currently loggedin Account has to be fetched.

I've endlessly browsed the Stormpath documentation and found no leads... Any ideas would be highly appreciated.

Thanks.


回答1:


The Servlet plugin has not support for social accounts yet. When you login with the Form then the Servlet is aware of that and puts the retrieved account in a cookie for later use. However, in the case of Social Logins, the servlet plugin is not yet aware of the Social Account Stores. I have just created this issues, you can subscribe to it in order to get notified about any progress of this feature.

It is relevant to mention that IDSite does actually support Social Account Stores. In your Spring/SpringBoot app you only need to do this in order to use it:

stormpath.web.idSite.enabled = true

When you enable it, you will be using Login/Registration/Forgot/etc pages from IDSite rather than the locally available ones.



来源:https://stackoverflow.com/questions/34228709/is-there-a-way-to-get-socially-signed-in-user-from-servlet-request-using-stormpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!