简体   繁体   中英

Java scribe client with OAuth 2 Resource Owner Password Credentials

I am building a mobile app that uses the Authorization Grant type "Resource Owner Password Credentials"

Tested the code in Ruby with the "oauth2" gem and it works fine

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 code

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(); 

How can I provide the username and password in Scribe (or with other library preferably compatible with Android)?

Right now I cannot find a way to do this with Scribe extending "DefaultApi20".

I understand now that this is just a POST request

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM