我正在尝试编写一个Spring Boot应用程序,它将使用Google单一登录(SSO)对用户进行身份验证(可能是任何其他SSO提供程序,如Facebook--此示例仅使用Google)。Spring Boot和Google SSO
我跟着几个教程和一个非常基本的设置提出了:
appplication.properties:
security.oauth2.client.client-id: xxx
security.oauth2.client.client-secret: yyy
security.oauth2.client.access-token-uri=https://www.googleapis.com/oauth2/v3/token
security.oauth2.client.user-authorization-uri=https://accounts.google.com/o/oauth2/auth
security.oauth2.client.client-authentication-scheme=query
security.oauth2.client.scope=profile,email
security.oauth2.resource.user-info-uri=https://www.googleapis.com/plus/v1/people/me
security.oauth2.resource.prefer-token-info=false
控制器:
@RestController
public class ExampleController {
@RequestMapping("/")
String hello(OAuth2Authentication authentication) {
return "Hello " + authentication.getName();
}
@RequestMapping("/details")
Object details(OAuth2Authentication authentication) {
return authentication.getUserAuthentication();
}
}
一切正常,在浏览器,我会提示输入我的Google凭据,只有在这之后我才能看到可以访问我的端点。
问题是我想以编程方式访问此API(例如使用cUrl
或RestClient
)。
我试过如下:
curl xxx:[email protected]:8080/my-api/oauth/token -d grant_type=client_credentials
,但得到如下回应:
{"timestamp":1466365089477,"status":403,"error":"Forbidden","message":"Expected CSRF token not found. Has your session expired?","path":"/my-api/oauth/token"}
我在努力寻找如何与SSO春天引导蜜蜂编程工作的一些好的文档或教程。有人可以解释我缺少的东西吗?或者指向一些具有完整功能的多用户API示例的工作教程?
感谢您的链接。稍后会进行测试,但看起来很有希望! – Smajl
似乎工作,但我仍然无法弄清楚如何编写我的休息客户端请求(cUrl或类似的实用工具)连接到API ... – Smajl