Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed changes for the API to work with Facebook OAuth v2. Instruction... #1

Merged
merged 1 commit into from
Nov 15, 2012

Conversation

JavRok
Copy link

@JavRok JavRok commented Mar 12, 2012

...s on 'CakePHP-Api-Datasources' project

@ProLoser
Copy link
Member

Were you using this in conjunction with the Apis plugin? And if so, were you able to put together a Facebook Api plugin? Been meaning to do this for a little while now.

@ProLoser
Copy link
Member

I'm poking around your forks and reviewing some of the OAuth spec.

I'm curious, have you taken a look at this plugin? https://github.com/ProLoser/CakePHP-Github

It's done using OAuth v2. I'm wondering if I implemented it incorrectly or if you just didn't know about it.

@JavRok
Copy link
Author

JavRok commented Mar 12, 2012

Hi Dean, and thanks for the quick reply.

I didn't see Github example. It would've saved me a few hours...
Anyway, it's my first and only example with OAuth V2, so I'm not sure if the problems I found are due to the protocol or Facebook API:

1- Requests were using http -> I put on the method map 'scheme' => 'https' and it worked (I saw you put it on beforeRequest() ). Also 'version' => '2.0' was needed.

2- I found 3 different urls when normally there are 2, that's why I had to create 'oauth_acess_token' and use it on getOAuthAccessTokenV2() :

authorization -> **https://www.facebook.com/dialog/**oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL
app authentication -> **https://graph.facebook.com/oauth**/access_token?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&client_secret=YOUR_APP_SECRET&code=THE_CODE_FROM_ABOVE
read data -> **https://graph.facebook.com/**me

3 - This same request (getOAuthAccessTokenV2) was failing because a 'redirect_uri' param was missing. I put one and still not working. This Stackoverflow article saved me, it needs to be exactly the same URL than previous request

4- And finally I got this error response and I had to extract from OAuth 2.0 draft doc that only "OAuth access_token" was necessary on "Authentication" HTTP param. Maybe other params are allowed, but you're the expert on that.

I found your plugins amazingly useful, but maybe a little more documentation or examples would have helped a lot. For example I'm not sure how to use the 'method maps' or 'schemes' on my behalf.

You're free of using this info I gave you and enhance the code to upload a Facebook plugin. I hope I could help.

Thanks

@ProLoser
Copy link
Member

So you my Github code doesn't work for facebook? Then my next test would be to ensure your facebook code works for Github, and finally to decide the best way to abstract the 2 solutions (as I'm not entirely sure requiring people to override the constructor is a great idea).

As for the map, that part is what makes the whole plugin FAKKING AWESOME and you need to do it.

I would actually recommend you creating that Facebook plugin you outlined (although I'll try walking through your instructions and doing it too) instead of just documenting it. As for the map, the way it works is thus:

  1. Read the target API documentation for potential query endpoints
  2. Create a 'section' under a CRUD action. For example, in Github a 'section' might be 'repos' or 'issues', etc. A body of data that you will query on.
  3. Inside the section, add the url to that end-point as an array key, with all the parameters it takes as array values. If the end-point takes optional parameters (such as limit, page, sort, etc) put those inside a sub-array called 'optional'. Remember, you can use :param1 and :param2 etc as tokens if they need to be inserted in the middle of the url (instead of the normal ?param=val approach)
  4. In your find('all'), set the 'fields' key to the section name and populate your 'conditions' array with the necessary parameters.
  5. The 'Map' will be searched under the section you specified for a url that has all of it's required parameters met, and then it will use that to query.

That's it! Hopefully this crappy short explanation isn't too confusing, but look at some existing plugins for reference. I would have given some applicable Facebook url examples but their api seems to be fairly.... static. Almost everything appears to use 1 end-point, and the only parameter you really NEED to pass is the id of whatever it is you're looking at. There is almost no need for sections.

ProLoser added a commit that referenced this pull request Nov 15, 2012
Proposed changes for the API to work with Facebook OAuth v2. Instruction...
@ProLoser ProLoser merged commit a72cde5 into CakePHP-Copula:master Nov 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants