我正在构建一个使用授权授予类型“资源所有者密码凭据”的移动应用
使用“oauth2”gem 在 Ruby 中测试代码,效果很好
client = OAuth2::Client.new('the_client_id', 'the_client_secret', :site => "http://example.com")
access_token = client.password.get_token('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="94e1e7f1e6d4f1ecf5f9e4f8f1baf7fbf9" rel="noreferrer noopener nofollow">[email protected]</a>', '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 ('<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d7a2a4b2a597b2afb6baa7bbb2f9b4b8ba" rel="noreferrer noopener nofollow">[email protected]</a>', '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”来执行此操作。
最佳答案
我现在明白这只是一个 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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="780d0b1d0a1619151d450d0b1d0a381d00191508141d561b1715" rel="noreferrer noopener nofollow">[email protected]</a> \
-F password=sekret
关于具有 OAuth 2 资源所有者密码凭证的 Java scribe 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19879853/