Scribe 的 Oauth 问题

发布于 2024-12-22 05:25:12 字数 1486 浏览 1 评论 0原文

我正在使用 scribe 来制作一个支持 oauth 的应用程序。我没有发现 Twitter 的问题,但是在使用 facebook 时我遇到了问题...

这是在 twitter oauth 上运行的代码

OAuthService s = /* ... Facebook oauth init ... */
final Token requestToken = s.getRequestToken();
final String authURL = s.getAuthorizationUrl(requestToken);

它在第二行给了我一个错误:

12-20 10:01:31.475: E/AndroidRuntime(5405): java.lang.UnsupportedOperationException: Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there
12-20 10:01:31.475: E/AndroidRuntime(5405):     at org.scribe.oauth.OAuth20ServiceImpl.getRequestToken(OAuth20ServiceImpl.java:45)

我知道它说我可能会使用 getAuthorizationUrl ..但我必须传递一个 requestToken...

你能帮我吗?

任何有关 Scribe 和 Facebook 的示例都会很有帮助,

谢谢!

PS:Windows Live 也有同样的问题! =(

编辑:

我一直在查看 Scribe 库的源代码,我发现了一些东西

https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java

这里我们可以看到我可以使用 null 参数调用 getAuthorizationUrl(...) 因为它不使用它...但我认为现在的问题是配置未填充...

是我初始化 facebook 服务的方式:

new ServiceBuilder()
    .provider(FacebookApi.class)
    .apiKey(....)
    .apiSecret(....)
    .scope("email,offline_access")
    .callback("oauth://facebook")
    .build();

这 这是正确的吗

I'm using scribe for making an app that has oauth support. I didn't found problems With Twitter, but when using facebook I have problems...

This is the code that works on twitter oauth

OAuthService s = /* ... Facebook oauth init ... */
final Token requestToken = s.getRequestToken();
final String authURL = s.getAuthorizationUrl(requestToken);

It gives me an error at the second line:

12-20 10:01:31.475: E/AndroidRuntime(5405): java.lang.UnsupportedOperationException: Unsupported operation, please use 'getAuthorizationUrl' and redirect your users there
12-20 10:01:31.475: E/AndroidRuntime(5405):     at org.scribe.oauth.OAuth20ServiceImpl.getRequestToken(OAuth20ServiceImpl.java:45)

I know that it says that I might use getAuthorizationUrl... But I have to pass a requestToken...

Could you please help me?

It would be helpful any example with Scribe and Facebook

Thanks!

PS: Same problem with Windows Live ! =(

EDIT:

I have been looking at the source code of the Scribe library and I found something

https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/oauth/OAuth20ServiceImpl.java

Here we can see that I can call the getAuthorizationUrl(...) with null parameter because it doesn't use it.... But I think the prioblem now is that the config isn't filled...

here is how I initialize facebook service:

new ServiceBuilder()
    .provider(FacebookApi.class)
    .apiKey(....)
    .apiSecret(....)
    .scope("email,offline_access")
    .callback("oauth://facebook")
    .build();

Is this correct?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独自唱情﹋歌 2024-12-29 05:25:12
private static final Token EMPTY_TOKEN = null;

OAuthService service = new ServiceBuilder()
                           .provider(FacebookApi.class)
                            .apiKey(apiKey)
                            .apiSecret(apiSecret)
                             .callback("http://www.example.com/oauth_callback/")
                              .build();
 String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);

您现在需要将用户重定向到此 URL,并让他自行验证以从 Facebook 获取代码。

对于几乎所有主要的誓言,都有大量的示例和非常好的文档
这里的系统

适用于 Facebook

FacebookExample

对于所有主要提供商
抄写示例目录

编辑

看完讨论后,我的建议是充分了解 Oauth1 和 Oauth2。

private static final Token EMPTY_TOKEN = null;

OAuthService service = new ServiceBuilder()
                           .provider(FacebookApi.class)
                            .apiKey(apiKey)
                            .apiSecret(apiSecret)
                             .callback("http://www.example.com/oauth_callback/")
                              .build();
 String authorizationUrl = service.getAuthorizationUrl(EMPTY_TOKEN);

All you now need to redirect user to this URL and let him verify them self to get code from facebok.

There are a good amount of example with very good documentation for almost all major Oath
system

here is for Facebook

FacebookExample

For all major providers
Scribe Example Directory

Edit

After looking at the discussion my suggestion is to get a full understanding about Oauth1 and Oauth2.

荆棘i 2024-12-29 05:25:12

你全都错了。 OAuth 2 协议永远不会像 OAuth 1 那样返回请求令牌。Oauth

1 执行 HTTP POST 请求并返回未经授权的请求令牌。然后,您必须授权您的未授权令牌才能接收授权令牌(这是 2 个 HTTP 调用)。

另一方面,Oauth 2 没有请求令牌流,您需要对授权令牌执行 HTTP GET(仅 1 个 HTTP 调用)。因此,Scribe 为何说您需要调用 getAuthorizedUrl

请参阅此 Facebook 示例< /a>,了解如何使用 OAuth 2 检索授权令牌。

You've got it all wrong. OAuth 2 Protocol never returns a request token like OAuth 1.

Oauth 1 does an HTTP POST request and returns an unauthorized request token. Then, you will have to authorize your unauthorized token to receive an authorized token (That's 2 HTTP call).

Oauth 2, on the other hand, doesn't have a request token flow, you will need to do an HTTP GET for an authorization token (1 HTTP call only). Hence why Scribe says that you need to call getAuthorizedUrl.

See this Facebook Example, to see how to retrieve an authorized token using OAuth 2.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文