我想保护我的 Spring RESTful 后端。一种方法(正确的?)是使用 OAuth 2.0,如下所示:
http://www.youtube.com/watch?v=8uBcpsIEz2I http://www.youtube.com/watch?v=8uBcpsIEz2I
在我的架构中,资源服务器和授权服务器ARE NOT同一实体。我实际上只是提供一些 JSON REST 服务。没有用户界面。如果我读到OAuth2 RFC https://www.rfc-editor.org/rfc/rfc6749#page-6他们只是说:
授权服务器和资源服务器的交互
超出了本规范的范围。授权服务器
可以是与资源服务器相同的服务器或单独的实体。
单个授权服务器可以发出接受的访问令牌
多个资源服务器。
我发现了一个很好的图表云铸造网 http://blog.cloudfoundry.com/2012/10/09/securing-restful-web-services-with-oauth2/(与上面的 YouTube 视频相关)我用它来说明我的观点:
“令牌”提供商:例如,这可以/应该是 google 或 facebook。
RESTful 后端:这实际上是我的代码。 Spring RESTful 服务,例如:
@Controller
@RequestMapping("/api/v1")
public class MyResourceToProtect {
@Autowired
private MyService service;
@RequestMapping(value = "/resource/delete/{name}",
method = RequestMethod.DELETE,
consumes = MediaType.APPLICATION_JSON_VALUE,
headers = "Content-Type=application/json")
@ResponseStatus(HttpStatus.OK)
public void delete(@PathVariable("name") String name) {
service.delete(name);
}
}
(这只是一些示例代码)
现在我的问题是:是否可以以某种方式验证 AuthServer(Facebook、Google)生成的访问令牌?我知道我需要在资源服务器上的某个位置有一个“令牌到用户”映射(数据库)。基本上我想设计我的 RESTful API,就像 PayPal 的 API 一样:
https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/ https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/
但是,如果我想使用 Facebook 或 Google 作为身份验证提供商,如何处理步骤 1 和 2?这可能吗?
附加想法:可能我需要提供自己的/oauth2/token
端点,然后委托给底层 AuthProvider。