【问题标题】:Java scribe client with OAuth 2 Resource Owner Password Credentials具有 OAuth 2 资源所有者密码凭证的 Java scribe 客户端
【发布时间】:2013-11-21 16:34:18
【问题描述】:

我正在构建一个使用授权授予类型“资源所有者密码凭据”的移动应用

使用“oauth2” gem 测试了 Ruby 中的代码,它工作正常

client = OAuth2::Client.new('the_client_id', 'the_client_secret', :site => "http://example.com")
access_token = client.password.get_token('user@example.com', 'sekret')
puts access_token.token

Java 代码

OAuthService service = new ServiceBuilder()
        .provider(MyApi.class)
        .apiKey("the_client_id")
        .apiSecret("the_client_secret")
        .debug()
        .build();
// the next step should provide ('user@example.com', 'sekret')
// because I am using "Resource Owner Password Credentials"
// http://tools.ietf.org/html/draft-ietf-oauth-v2-31#page-53
Token requestToken = service.getRequestToken(); 

如何在 Scribe(或其他最好与 Android 兼容的库)中提供用户名和密码?

现在我找不到使用 Scribe 扩展“DefaultApi20”的方法。

【问题讨论】:

    标签: java android oauth oauth-2.0 scribe


    【解决方案1】:

    我现在明白这只是一个 POST 请求

    curl -i http://localhost:3000/oauth/token \
      -F grant_type=password \
      -F client_id=the_client_id \
      -F client_secret=the_client_secret \
      -F username=user@example.com \
      -F password=sekret
    

    【讨论】:

    • 您有没有找到使用 Scribe 本身的方法?
    • @TomLeese 我用Retrofit作为客户端。public Interface MyService { @FormUrlEncoded @POST("/oauth/token") Token login(@Field("grant_type") String grant_type, @Field("client_id") String client_id, @Field("client_secret") String client_secret, @Field("username") String email, @Field("password") String pin); }
    • 你的意思是根本不需要抄写员吗?
    • 是的,您可以使用 HTTP 请求处理所有内容或使用 Retrofit
    猜你喜欢
    • 1970-01-01
    • 2016-03-03
    • 2015-04-01
    • 2013-10-17
    • 2014-07-09
    • 2015-01-06
    • 2016-12-31
    • 2023-03-19
    • 1970-01-01
    相关资源
    最近更新 更多