我正在尝试为我的Android应用程序构建oauth身份验证。 我使用ZF2和PECL OAuthProvider构建了服务器端,但现在我正在尝试构建客户端。
我尝试在请求令牌请求失败的路标,所以我切换到Scribe,但它并不是更好:
当我尝试获取Request令牌时,我得到一个例外。这是我的Trace(在调试模式下)
04-20 23:03:40.768: I/System.out(10677): obtaining request token from http://192.168.1.198:88/oauth/requesttoken
04-20 23:03:40.778: I/REQUEST(10677): http://192.168.1.198:88/oauth/requesttoken
04-20 23:03:40.778: I/System.out(10677): setting oauth_callback to oob
04-20 23:03:40.778: I/System.out(10677): generating signature...
04-20 23:03:40.838: I/System.out(10677): using base64 encoder: CommonsCodec
04-20 23:03:40.958: I/System.out(10677): base string is: POST&http%3A%2F%2F192.168.1.198%3A88%2Foauth%2Frequesttoken&oauth_callback%3Doob%26oauth_consumer_key%3D0afc84167f8f5c0134d88599c7dbdabf6e05de12%26oauth_nonce%3D345688132%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1366491820%26oauth_version%3D1.0
04-20 23:03:40.958: I/System.out(10677): signature is: O2gik5ufQISAluRS5sDyZcUy2SQ=
04-20 23:03:40.968: I/System.out(10677): appended additional OAuth parameters: { oauth_callback -> oob , oauth_signature -> O2gik5ufQISAluRS5sDyZcUy2SQ=
04-20 23:03:40.968: I/System.out(10677): , oauth_version -> 1.0 , oauth_nonce -> 345688132 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> 0afc84167f8f5c0134d88599c7dbdabf6e05de12 , oauth_timestamp -> 1366491820 }
04-20 23:03:40.968: I/System.out(10677): using Http Header signature
04-20 23:03:40.978: I/System.out(10677): sending request...
04-20 23:03:41.018: W/System.err(10677): org.scribe.exceptions.OAuthConnectionException: There was a problem while creating a connection to the remote service.
04-20 23:03:41.028: W/System.err(10677): at org.scribe.model.Request.send(Request.java:69)
04-20 23:03:41.028: W/System.err(10677): at org.scribe.oauth.OAuth10aServiceImpl.getRequestToken(OAuth10aServiceImpl.java:59)
这是代码(尽可能简单):
OAuthService service = new ServiceBuilder()
.provider(OAuthApi.class)
.apiKey(Const.CONSUMER_KEY)
.apiSecret(Const.CONSUMER_SECRET)
.debug()
.build();
Token requestToken = service.getRequestToken();
Log.i("Token", requestToken.getToken());
我的OAuthApi基于示例,也很简单:
public class OAuthApi extends DefaultApi10a {
@Override
public String getRequestTokenEndpoint()
{
Log.i("REQUEST ", Const.SERV+"oauth/requesttoken");
return Const.SERV+"oauth/requesttoken";
}
@Override
public String getAccessTokenEndpoint()
{
return Const.SERV+"oauth/accesstoken";
}
@Override
public String getAuthorizationUrl(Token requestToken)
{
return String.format(Const.SERV+"oauth/authorize?token=%s", requestToken.getToken());
}
}
我做错了什么? Scribe在Android上有限制吗?
感谢。