0

I have a wordpress site which have a form and when is submitted I want to send the data to an external API. In order to access the external API and I need to pass a 2Oauth authorization. How I can achieve this without showing in the javascript the client_id & client_secret? I'm not restricted to use only javascript but I didn't found a wordpress way to do that.

Thanks.

  • You can write your own WP AJAX handler and pass you data to this handler, which in turn would pass it further via WP HTTP API using your client_id and client_secret (stored in database or directly within PHP code). Once I solved the similar problem this way. – Ivan Shatsky Jul 4 at 22:33
0

I'd suggest you should call the API from the server, not from the client. This should be possible when the form is submitted and as you say doing OAuth from the browser introduces a lot more issues.

This is a fair bit of work, so I'd suggest this general structure to the way you approach it:

  1. Figure out how to do the OAuth authentication you need and calling the remote API in plain PHP code outside of Wordpress. This is difficult enough, you don't want to try to make this work inside Wordpress first.
  2. Once you can do this, do the simplest possible integration with Wordpress - e.g. in a plugin with e.g. a shortcode just to test that you can make this code run from inside Wordpress ok.
  3. Once you've done this, figure out how to call the code when the form is submitted, e.g. by hooking in to a Wordpress action that runs when your form is submitted, or finding some other way to run code on the server when the form is submitted.

HTH, please post if you have any followup or more specific questions.

| improve this answer | |

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.