1

I am trying to authorise with an Viagogo API using oauth in my custom module (i have my credentials from Viagogo). I can construct the initial URL OK but the redirect response from the API is a relative reference with an absolute path i.e. /Public/SimpleOAuthAccessRequest/Authorize?oauth_token=Y%34hg5k34jhg5%3D

Which in turn is throwing a missing schema error using drupal_http_request.

object(stdClass)#466 (4) { ["error"]=> string(14) "missing schema" ["code"]=> int(-1002) ["redirect_code"]=> string(3) "302" ["redirect_url"]=> string(87) "/Public/SimpleOAuthAccessRequest/Authorize?oauth_token=Y%2Fbm9asdfasdfdsfjJfdd3D"

How can i get around this?

Is there a simpler way my custom module can authorise with oauth and access this API instead of my having to write this connector? The PHP code sample provided by Viagogo is using CURL and works fine outside of Drupal but once I bring the functions inside my custom module it doesn't work hence me using drupal_http_request.

  • Why not just wrap those API functions in a class and use that instead of drupal_http_request()? But if you can't do that for some reason, just prepend the scheme and host to the path you get back from the API (i.e. qualify it) before you pass it on – Clive Aug 27 '14 at 17:04
  • Am i missing something in Drupal that can handle this oauth authentication out of the box @Clive. Could you provide an example? – Lee Woodman Aug 27 '14 at 17:09
  • 1
    Drupal doesn't have anything, no...I had a quick look at the API code and if it was me I'd just use that directly, rather than trying to use Drupal's API. That's from the vendor, you can be pretty sure it works. Also if the problem's being caused by a redirect that happens inside drupal_http_request(), it stands to reason you could only 'fix' it by altering that function – Clive Aug 27 '14 at 17:11
  • @Clive as in the sample code they provided? Yes that works fine if i run it as a file outside of Drupal (in root) but ideally i want it inside a custom module. Once i bring their sample code inside my custom module CURL refuses to return anything. – Lee Woodman Aug 27 '14 at 17:13
  • Drupal doesn't get involved with curl at all, it doesn't really make sense that the code would work on the same server, but not when it's in a .module file (which after all is just included and processed like any other PHP file). I don't think drupal_http_request is an option if it doesn't like the redirect path it's given, so you're left with either altering that function so it does like the path, or implementing it manually. If you're going manually the code right from the vendor would be best – Clive Aug 27 '14 at 17:24
0

I was trying to dump out the results coming back from my API call one step too early and before the redirect (to present the token) had taken place so inside Drupal it didn't appear as if anything was happening.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.