具有 OAuth 2 资源所有者密码凭证的 Java scribe 客户端

标签 java android oauth oauth-2.0 scribe

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

使用“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/

相关文章:

java - 无法在列表中生成随机分散的真值和假值

java - 0x80000000 在 Java 中如何等同于 -2147483648?

java - 有没有办法打开某种 JVM 日志记录,以便我可以看到类加载期间发生的情况等

android - 代号一 - AutoCompleteTF 不良行为

java - Android 中的 Groovy 扩展模块?

angular - msal Angular - 在路由上使用 MsalGuard 进行身份验证时连续重新加载

php - 将多个 oauth 帐户链接到单个用户 : what's considered safe practice and what's not?

java - 部署 Apache Camel 项目

java - 无法使用 Visual Studio 2015 编辑 Xamarin .axml 布局文件

c# - Owin OAuth 上下文 : Frontend login sending Json