Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Android上的Google API Java客户端,POST请求似乎无法通过使用OAuth的Google应用程序引擎应用程序进行身份验证_Android_Google App Engine_Oauth_Google Api_Google Api Java Client - Fatal编程技术网

使用Android上的Google API Java客户端,POST请求似乎无法通过使用OAuth的Google应用程序引擎应用程序进行身份验证

使用Android上的Google API Java客户端,POST请求似乎无法通过使用OAuth的Google应用程序引擎应用程序进行身份验证,android,google-app-engine,oauth,google-api,google-api-java-client,Android,Google App Engine,Oauth,Google Api,Google Api Java Client,我有一个Android客户端,需要使用OAuth通过python Google应用程序引擎应用程序进行身份验证。我跟着 并且能够使用HTTP Get请求成功地执行此操作。Android客户端使用com.google.api.client包完成以下任务: OAuthHmacSigner _signer; HttpTransport TRANSPORT = new NetHttpTransport(); _signer = new OAuthHmacSigner(); _signer.clientS

我有一个Android客户端,需要使用OAuth通过python Google应用程序引擎应用程序进行身份验证。我跟着

并且能够使用HTTP Get请求成功地执行此操作。Android客户端使用com.google.api.client包完成以下任务:

OAuthHmacSigner _signer;
HttpTransport TRANSPORT = new NetHttpTransport();
_signer = new OAuthHmacSigner();
_signer.clientSharedSecret = CONSUMER_SECRET;

// STEP1: get a request token
OAuthGetTemporaryToken requestToken = new OAuthGetTemporaryToken(REQUEST_TOKEN_URL);
requestToken.consumerKey = CONSUMER_KEY;
requestToken.transport = TRANSPORT;
requestToken.signer = _signer;
requestToken.callback = "http://my_app_specific_callback";
requestTokenResponse = requestToken.execute();
OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(AUTHORIZE_URL);
authorizeUrl.temporaryToken = requestTokenResponse.token;
// at this point, redirect the user using a WebView to the URL string returned by authorizeUrl.build().  Continue below once the user has granted request.

// STEP2: get an access token
_signer.tokenSharedSecret = requestTokenResponse.tokenSecret;
OAuthGetAccessToken accessToken = new OAuthGetAccessToken(ACCESS_TOKEN_URL);
accessToken.consumerKey = CONSUMER_KEY;
accessToken.signer = _signer;
accessToken.transport = TRANSPORT;
accessToken.temporaryToken = requestTokenResponse.token;
accessTokenResponse = accessToken.execute();

// STEP3: use the access token acquired above to access a protected resource
_signer.tokenSharedSecret = accessTokenResponse.tokenSecret;
OAuthParameters parameters = new OAuthParameters();
parameters.consumerKey = CONSUMER_KEY;
parameters.token = accessTokenResponse.token;
parameters.signer = _signer;
HttpRequestFactory factory = TRANSPORT.createRequestFactory(parameters);
HttpRequest req = factory.buildGetRequest(new GenericUrl(PROTECTED_URL_GET_USER_EMAIL));
com.google.api.client.http.HttpResponse resp = req.execute();
在上面的代码片段中,所有3个步骤都可以正常工作。在我的Google App Engine服务器上,我检查了对受保护的\u URL\u GET\u用户\u电子邮件发出的GET请求,它包含一个正确的身份验证HTTP头:

'Authorization': 'OAuth oauth_consumer_key="shiprack-test1.appspot.com", oauth_nonce="...", oauth_signature="...", oauth_signature_method="HMAC-SHA1", oauth_timestamp="...", oauth_token="..."'
使用GAE上的oauth python包(google.appengine.api.oauth),我的服务器能够对用户进行身份验证并确定用户的电子邮件地址(oauth.get\u current\u user())

但是,问题是当我将受保护的URL\u GET\u USER\u电子邮件转换为HTTP Post请求时。我就是这样做的:

Map<String, String> paramsMap = new HashMap<String, String>();
paramsMap.put("param1", "value1")
paramsMap.put("param2", "value2")
HttpRequest req = _httpRequestFactory.buildPostRequest(new GenericUrl(url), new UrlEncodedContent(paramsMap));
req.setFollowRedirects(true);
com.google.api.client.http.HttpResponse resp = req.execute();
Map paramsMap=newhashmap();
paramsMap.put(“param1”、“value1”)
paramsMap.put(“param2”、“value2”)
HttpRequest req=_httpRequestFactory.buildPostRequest(新的GenericUrl(url),新的UrlEncodedContent(paramsMap));
请求setFollowRedirects(真);
com.google.api.client.http.HttpResponse resp=req.execute();
但是现在,在GAE python服务器端,我无法确定当前用户。HTTP头包含相同的OAuth身份验证头(具有不同的nonce、时间戳和签名,但具有相同的OAuth令牌)。“param1”和“param2”在HTTP有效负载中。也许我的POST请求构造不正确

我使用python客户端的(Google App Engine支持团队)代码对我的GAE服务器进行身份验证。这也起作用了。。。原始客户机使用GET请求,甚至当我修改它以使用POST请求时。我注意到,在POST请求中,oauth参数作为URL编码的值包含在HTTP负载中,而不是HTTP头中。这是Oauth签名HTTP post请求的要求吗


提前谢谢

不幸的是,基于表单编码的HTTP内容参数的正确OAuth 1.0a编码尚未实现。我们收到了不少这样的请求。已经有一个开放的应用程序。

我发现并非所有由oauth签名的HTTP Post请求都会失败。只有那些具有url编码的表单数据和应用程序特定的键/值对。空HTTP Post请求(在HTTP头中嵌入Oauth参数)和HTTP Get请求一样工作正常。更多更新:任何包含URL编码数据的HTTP PUT请求都不工作。例如,如果我对application/json进行编码,GAE服务器就能够从我的Android客户端应用程序发送的oauth身份验证HTTP头(使用google客户端javaapi)确定经过身份验证的用户。另外,如果我提供的应用程序特定的负载数据也是URL编码的,那么我希望OAuthHmacSigner类自动将oauth参数添加为URL编码的负载数据。Oauth规范指出这些参数必须按字母顺序列出。但这并没有发生。对于任何试图这样做的人——将特定于应用程序的数据编码为application/json,并使用oauth凭据对其进行签名,这里有一篇关于如何确保json格式合法的好文章:啊,这解释了一切!谢谢亚尼夫。我想我应该使用application/json内容类型。从oauth签名的角度来看,您是否预见到了这方面的任何问题。我必须集中精力确保特定于应用程序的数据可以正确地进行json格式(并在服务器上解码)。