Suggestion: Allow lambdas for `parse` option
We noticed an inconsistency in how Facebook responds to OAuth requests during callbacks.
When sending an access token, Facebook responds with a Content-Type of text/plain while the body is actually application/x-www-form-urlencoded encoded. That's why mkdynamic/omniauth-facebook hardcodes the parse option to :query.
During error conditions however, Facebook responds with application/json and the body being a JSON encoded Hash giving more information about the error encountered. Due to the need for hardcoding the parser to query for the normal responses (as Facebook misreports the content type), the error responses are now no longer parsed correctly.
To test this, simply attempt two OAuth requests against facebook. One using correct application credentials (thus receiving the form encoded response) and one using a wrong application secret (thus receiving a JSON encoded error response).
Currently, I don't see a clean way to institute different parsing behaviours for different responses without monkey-patching. One has to either always rely on the reported content type or always use the same parser as defined via the parse option. I would thus like to suggest having the latter accept lambdas which would get passed the entire response (incl. headers) and return :query, :json, etc. as appropriate. The behaviour for non-lambda values would remain the same, thus ensuring backward compatibility.
Let me know what you think; I'd be happy to send a pull request.