【发布时间】:2018-08-04 01:29:08
【问题描述】:
我正在使用 oauth2-essentials 库,因为它是 uber 开发人员网站上推荐的 oauth 库之一,并且最近已更新。 我的代码如下所示:
executor = new HttpUrlConnectionExecutor();
OAuth2AuthorizationProvider provider = new BasicOAuth2AuthorizationProvider(
URI.create("https://login.uber.com/oauth/v2/authorize"),
URI.create("https://login.uber.com/oauth/v2/token"),
new Duration(1,0,3600) /* default expiration time in case the server doesn't return any */);
OAuth2ClientCredentials credentials = new BasicOAuth2ClientCredentials(
getString(R.string.uberClientId), getString(R.string.uberSecret));
uberOAuthClient = new BasicOAuth2Client(
provider,
credentials,
new LazyUri(new Precoded("my redirect url")) /* Redirect URL */);
generateUberOAuthToken("my phone number", "my password");
}
public void generateUberOAuthToken(final String uName, final String password){
new Thread() {
public void run() {
try {
uberOAuthToken = new ResourceOwnerPasswordGrant(
uberOAuthClient, new BasicScope("profile"), uName, password).accessToken(executor);
}
catch (Exception e){
e.printStackTrace();
}
}
}.start();
}
异常:org.dmfs.httpessentials.exceptions.UnauthorizedException:“https://login.uber.com/oauth/v2/token”身份验证失败。总是被抛出。我尝试删除重定向 url,因此它应该使用我仪表板中的默认值,并且我尝试在电话号码中添加 1 和/或破折号。当我请求访问令牌时,总是会抛出异常。我知道我的帐户设置正确,因为这在 iOS 中运行良好。我觉得我一定错过了一些明显的东西。还有其他人遇到这个问题吗?
【问题讨论】:
标签: android oauth-2.0 uber-api