我已成功分别使用openID和OAuth,但我无法让它们协同工作。
我做错了什么:
String userSuppliedString = "https://www.google.com/accounts/o8/id";
ConsumerManager manager = new ConsumerManager();
String returnToUrl = "http://example.com:8080/app-test-1.0-SNAPSHOT/GAuthorize";
List<DiscoveryInformation> discoveries = manager.discover(userSuppliedString);
DiscoveryInformation discovered = manager.associate(discoveries);
AuthRequest authReq = manager.authenticate(discovered, returnToUrl);
session.put("openID-discoveries", discovered);
FetchRequest fetch = FetchRequest.createFetchRequest();
fetch.addAttribute("email","http://schema.openid.net/contact/email",true);
fetch.addAttribute("oauth", "http://specs.openid.net/extensions/oauth/1.0",true);
fetch.addAttribute("consumer","example.com" ,true);
fetch.addAttribute("scope","http://www.google.com/calendar/feeds/" ,true);
authReq.addExtension(fetch);
destinationUrl = authReq.getDestinationUrl(true);
然后destinationUrl是
但是来自谷歌的响应 request_token缺失
为什么吗
答案 0 :(得分:1)
在上面的代码中,您已使用Attribute Exchange扩展参数添加了OAuth扩展参数。但由于OAuth和属性交换是不同的扩展,因此您必须为OAuth参数创建不同的扩展消息,然后将其添加到身份验证请求消息中。
但由于没有将OAuth参数添加到Authentication消息的机制,因此您必须创建这样的机制。您可以在以下链接中获取有关它的信息 http://code.google.com/p/openid4java/wiki/ExtensionHowTo
然后,您可以使用以下链接中提供的代码对此机制进行硬编码 http://code.google.com/p/openid4java/issues/detail?id=110&q=oauth