我正在创建一个移动应用程序,我想为用户提供注册/使用电子邮件或通过他们的facebook帐户的选择。
在过去的两天里,我读了很多东西,但我仍然不知道该怎么做。
我已经看到了下面的链接,但是它对我来说有点混乱,我想使用Spring (boot)堆栈,并使用。http://porterhead.blogspot.com.br/2013/01/writing-rest-services-in-java-part-4.html
我为rest身份验证找到的最好示例是这个http://www.codesandnotes.be/2014/10/31/restful-authentication-using-spring-security-on-spring-boot-and-jquery-as-a-web-client/,但是它是基于表单的,它不适用于移动应用程序。
申请在我脑海中的流程是:
之后的步骤对我来说也有点模糊。在这些检查之后,我应该返回给客户什么?如何为下列请求验证其令牌?
我读了很多书,但还是不能把这些点联系起来。任何帮助都是非常感谢的。
提前感谢!
发布于 2015-09-07 17:00:42
首先,当您将facebook-auth令牌发送到后端时,它会像spring-social一样由facebook库检查,而不是由spring安全性检查。所以我给你们举个春季社交的例子。
Facebook facebook = new FacebookTemplate(fbtoken, yourappname);
org.springframework.social.facebook.api.User facebookUser = facebook.userOperations().getUserProfile(); // throw exception if token is not authenticated
if(facebookUser.getId() != null){
return true;
}else{
throw new AuthenticationException(configProp.getProperty("invalid token"), HttpStatus.FORBIDDEN, HttpStatus.FORBIDDEN.value());
}在验证了facebook令牌之后,您必须为您的应用程序创建一个唯一的令牌,您可以通过
String token = UUID.randomUUID().toString()然后,您将保存在数据库中并返回到客户端。来自客户端的进一步请求,您已经从客户端发送了这个令牌,现在这个令牌将由spring安全性检查。
if(tokenValid){
//access your app
}else{
return "unauthorized user"
}在登出时,您将从数据库和客户端删除它。
https://stackoverflow.com/questions/32442786
复制相似问题