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

Added optional appsecret_proof configuration parameter. #323

Merged
merged 8 commits into from
Feb 1, 2014
Merged

Added optional appsecret_proof configuration parameter. #323

merged 8 commits into from
Feb 1, 2014

Conversation

nchelluri
Copy link
Contributor

No description provided.

@nchelluri
Copy link
Contributor Author

I wouldn't merge this in just yet. I am thinking, it probably makes more sense to pass in the appsecret and have Koala use OpenSSL to add the appsecret_proof param if there is an access token present. But, it should only do this if using the Graph API, since that is the only one that supports it.

What do you think?

@nchelluri
Copy link
Contributor Author

Better...

@@ -45,6 +46,8 @@ def api(path, args = {}, verb = "get", options = {}, &error_checking_block)
# This is explicitly needed in batch requests so GraphCollection
# results preserve any specific access tokens provided
args["access_token"] ||= @access_token || @app_access_token if @access_token || @app_access_token
args['appsecret_proof'] = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), Koala.config.appsecret, args['access_token']) if options[:appsecret_proof] && args['access_token'] && Koala.config.appsecret
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps also use double quotes here for consistency?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also break this line up -- it's really long. Putting the if on the line above will be much more readable.

I concur with @nielsomat that we probably don't need to offer overriding on a per-request basis. If someone wants it, they can submit a PR, but for now less code is better code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the quotes -- but the Ruby Style Guide suggests we use single quotes :)

https://github.com/bbatsov/ruby-style-guide#strings

@niels
Copy link

niels commented Sep 20, 2013

+1 from me in principle!

I would however set the default config in Koala itself, just like http_service is currently configured (https://github.com/arsduo/koala/blob/master/lib/koala.rb#L26). Further, I would rename the option to use_appsecret_proof for clarity.

Not sure if the option needs to remain overridable per-request as in your current implementation. Once you have your app secret configured, what's the benefit of disabling appsecret_proof for individual requests? The only one I see is to save the overhead incurred by generating a hash for every request. IMO using appsecret_proof at all only makes sense though when forbidding non-proofed calls via the app settings. When doing so, you can't send any non-proofed calls anyway, so… should we get rid of the override in order to promote safety? :)

Koala.configure do |config|
config.appsecret = app_secret
# see lib/koala/api/graph_api.rb
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would actually suggest triggering the app secret slightly differently -- there are applications out there that have to work with multiple Facebook applications within the context of the same Ruby app. (A good example is social marketing/brand management, the type of platform I was working on when I started Koala.) A global configuration wouldn't work for that situation.

Instead, what do you think of making the secret be the second parameter for the API initializer? That way, you could easily specify the secret to be used for proofing at the time you create the API. This has two additional bonuses -- it's consistent with the way we pass the secret into other Koala classes, and additionally, many applications don't use the Koala setup block (they just instantiate an API object) so this avoids the need to configure Koala somewhere else on application load for those apps.

# if secret is passed in, proof all the requests that API object makes
api = Koala::Facebook::API.new(token, secret)

@arsduo
Copy link
Owner

arsduo commented Sep 28, 2013

I really like this -- thanks for a great pull request. Having documentation and tests is a huge help as a maintainer.

I've posted some comments -- in particular, I've suggested a different mechanism for passing in the app's secret and enabling the proofing, since the current global approach (while a good solution for most use cases) won't work for Ruby applications that need to manage more than one Facebook app.

Let me know what you think about that and my other comments -- I'd love to get this into 1.8.

Best,

Alex

@nchelluri
Copy link
Contributor Author

Hi, sure, I'd be happy to make the changes.

What is your timeline for releasing 1.8? I'm a bit busy atm, but can probably fit it in if the release is not too soon. Could make end of October for sure.

If I get tired of my day job it might end up happening sooner :)

- updated readme accordingly
- updated tests accordingly
- cleaned up some code per code review
@nchelluri
Copy link
Contributor Author

Made all the changes I could think of; please let me know how you guys feel about this. Thanks for the feedback!

@nchelluri
Copy link
Contributor Author

Looks like the tests are failing because bundle install is failing to complete. I am not too sure what to do about this.

@arsduo
Copy link
Owner

arsduo commented Oct 26, 2013

I'll take a look at the Travis tests and get this merged in today; sorry about the delay. Looks great!

@arsduo
Copy link
Owner

arsduo commented Oct 26, 2013

The Travis tests were failing for various Ruby 1.8-compatible installations due to underlying gems requiring 1.9+. I think it's time to just cut off support for 1.8. Merging this in now!

@nchelluri
Copy link
Contributor Author

Hooray!

@nlsrchtr
Copy link

Great commit! Looking forward to this merge and the increase in security. Especially since tools like Buffer were hacked.

Thanks for your work, @nchelluri!

@arsduo
Copy link
Owner

arsduo commented Nov 15, 2013

The code is working, I'll merge it by this weekend and release 1.8rc2.

nlsrchtr pushed a commit to nlsrchtr/koala that referenced this pull request Nov 15, 2013
@arsduo
Copy link
Owner

arsduo commented Dec 17, 2013

Huh, I thought I merged this in. I'll take care of this soon, sorry about the delay.

@nlsrchtr
Copy link

👍

@adrienkohlbecker
Copy link

It seems this PR has not been merged before the 1.8.0 release, it's in the changelog but not in the code

@arsduo
Copy link
Owner

arsduo commented Feb 1, 2014

You're right. Not sure how that happened, I thought I merged that in. Fixing now.

@arsduo
Copy link
Owner

arsduo commented Feb 1, 2014

The new merged version is in integration testing on Travis -- I'll be releasing it and a few other internal changes as 1.9.0rc1 shortly, and will post here so you can test it.

Here's the final behavior for appsecrets:

  • If you provide an appsecret argument when initializing an API instance, it'll be included by default in all your requests: API.new(token, secret).get_object("/foo")
  • You can disable this on a per-request basis (if you really wanted to): API.new(token, secret).get_object("/foo", {}, appsecret_proof: false)
  • If you don't provide an appsecret (or you're making public API requests without a token), no appsecret_proof will be included.

The readme will be updated as well when this gets merged in.

Thanks and sorry about the mistake!

@arsduo arsduo merged commit 21694dc into arsduo:master Feb 1, 2014
@arsduo
Copy link
Owner

arsduo commented Feb 1, 2014

1.90rc1 is released -- let me know if you enounter any issues or have any questions around this! Otherwise I'll release the full gem soon.

@adrienkohlbecker
Copy link

Great! I'll try this out and report back if I find any issues.
Thanks

@adrienkohlbecker
Copy link

No issues so far

@arsduo
Copy link
Owner

arsduo commented Feb 5, 2014

Great, I'll release it this afternoon. Given the changes I really don't
expect any problems.
Am 05.02.2014 08:21 schrieb "Adrien Kohlbecker" notifications@github.com:

No issues so far

Reply to this email directly or view it on GitHubhttps://github.com//pull/323#issuecomment-34175958
.

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.

5 participants