matthiasnoback / microsoft-translator

PHP library for making calls to the Microsoft Translator V3 API
MIT License
39 stars 26 forks source link

ACS90007: Request method not allowed #1

Closed ivannpaz closed 11 years ago

ivannpaz commented 11 years ago

While to trying to get the accessTokens the call fails. I managed to somehow pinpoint it to this particular error "ACS90007: Request method not allowed":

array(4) {
  'type' =>
  int(2)
  'message' =>
  string(117) "file_get_contents(https://datamarket.accesscontrol.windows.net/v2/OAuth2-13): failed to open stream: operation failed"
  'file' =>
  string(75) "/vagrant/site/vendor/kriswallsmith/buzz/lib/Buzz/Client/FileGetContents.php"
  'line' =>
  int(59)
}
ivannpaz commented 11 years ago

Update on this:

I manage to get it working by modifying the SilexProvider (I forgot to mention before I was using it from your own Silex provider) by setting the verifyPeer to false...

$app['microsoft_oauth.access_token_provider.browser.client'] = $app->share(function() {
    $fileGetContents = new FileGetContents();
    $fileGetContents->setVerifyPeer(false);
    return $fileGetContents;
});

The extra implications this might have right now escape my mind, but would it be ok to have some params (such as this) available during the service instantiation?

matthiasnoback commented 11 years ago

Thanks for submitting this issue. When I ran the functional unit test locally (with PHP 5.4 and PHPUnit 3.7.21), I had the same problem. The solution is not to disable peer verification (which is not really good for security reasons).

The solution (at least in my case) was to use a different client for the Buzz browser, so instead of FileGetContents try Curl:

use Buzz\Client\

$app['microsoft_oauth.access_token_provider.browser.client'] = $app->share(function() {
    return new Curl();
});

You don't really need to modify the file containing the service provider itself, you can add this code after you have instantiated your application and registered the service provider.

Within a few days I will push a solution for the problem. I think the best solution would be to add a configuration flag for the type of Buzz browser client developers would want to use.

matthiasnoback commented 11 years ago

Strange though that the error is "Request method not allowed"!

ivannpaz commented 11 years ago

Hi @matthiasnoback thanks for the fast reply!

I did the "patching" on a forked version of your provider to get it going fast as I wanted to see how the prototype of my app would do. Needless to say I didnt like my solution at all :) I will try your suggestion in a while!

About the error, at first I though it had something to do with the request being done via GET instead of POST... turns out it was a different thing, but with the server error message of another... maybe too generic error...

matthiasnoback commented 11 years ago

Hi @ivannpaz, you're welcome. In fact, you are the first to submit any serious issue to an open source project that I maintain, so it only seemed logical to attend to it very quickly ;)

ivannpaz commented 11 years ago

HI @matthiasnoback, I will close this issue then, as it was mainly related to the configuration passed on the SilexProvider and not on this package as such. Again, thanks for your support!

matthiasnoback commented 11 years ago

@ivannpaz I've tagged the older versions as 0.1.0. Then I changed the default browser client from FileGetContents to Curl and push a new version, 0.2.0 for it. So, everything should be fine again after you run composer update.

ivannpaz commented 11 years ago

@matthiasnoback million thanks for tagging the releases!

matthiasnoback commented 11 years ago

@ivannpaz It was a good reason to finally do this :)