【发布时间】:2012-10-30 06:53:21
【问题描述】:
我在这里搜索了一下,但找不到我的问题的答案。
我使用 spring-sec-oAuth 2.0 (1.0.0.RC2a) 实现 oAuth 客户端。正确设置 beans.xml 后,我很高兴地得到了一个有效的令牌,一切看起来都很好。然后,我想使用日历 API - 我不确定如何调用来获取日历对象。
我的(相关)设置:(spring-servlet.xml)
<!--apply the oauth client context-->
<oauth:client id="oauth2ClientFilter" />
<oauth:resource id="google"
type="authorization_code"
client-id="<my client id>"
client-secret="<my client secret>"
access-token-uri="https://accounts.google.com/o/oauth2/token"
user-authorization-uri="https://accounts.google.com/o/oauth2/auth"
scope="https://www.googleapis.com/auth/calendar"
client-authentication-scheme="form"
pre-established-redirect-uri="https://ohad.sealdoc.com/oauth2-client/hello" />
<bean id="googleClientService" class="com...GoogleClientServiceImpl">
<property name="butkeDemoRestTemplate">
<oauth:rest-template resource="google" />
</property>
和实现类:
public class GoogleClientServiceImpl implements DemoService
{
private RestOperations butkeDemoRestTemplate;
@Override
public String getTrustedMessage()
{
String dataUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList?minAccessRole=writer";
Calendar service = butkeDemoRestTemplate.getForObject(dataUri, Calendar.class);
return "demo";
}
}
这样做的结果是:
请求处理失败;嵌套异常是 错误=“无效请求”, error_description="{errors=[{domain=usageLimits, 原因=accessNotConfigured,消息=未配置访问}],代码=403, message=访问未配置}"
当然,我在“getTrustedMessage()”中做错了,所以我听说要咨询专家...我确实想使用 OAuth2RestTemplate,但我怎么知道我应该使用的 URI?搜索(谷歌)后,我只找到了谷歌代码的示例,他们使用谷歌 oAuth(我不想使用 - 我宁愿为我的客户端使用 Spring 实现)
有什么想法吗?
【问题讨论】:
-
能否请您指出一篇不错的文章,我可以在其中实现我自己的基于 Spring Security 的 OAuth 应用程序并使用 Google 作为提供者。真的很感激。
-
@Anand 我认为最好的文章是 Spring-Security-oAuth wiki 页面。您拥有编写客户端和受保护资源的所有详细信息,身份提供者将是 google,因此您必须配置受保护资源的 XML。 github.com/SpringSource/spring-security-oauth/wiki/oauth2
-
如何以及何时将用户重定向到同意页面?我正在尝试使用 Oauth2 & Google 作为提供者来实现用户注册。 stackoverflow.com/questions/20664846/…
标签: spring-security google-api oauth-2.0 google-calendar-api