Incongruous user creation due to :respond_to_suspicous_request


(Benjamin Miller) #1

Heyo.

I’m trying to integrate a salesforce trigger that creates a Discourse account over the api. I’ve generated a API key for the default system user who is admin, and when I create the user from the ruby repl it works fine but when its coming from salesforce it gets caught up in the titular before action.

Here’s the log I’m seeing:

Started POST "/users.json" for 184.23.159.2 at 2019-02-07 18:22:36 +0000
Processing by UsersController#create as JSON
  Parameters: {"api_key"=>"[FILTERED]", "api_username"=>"system", "username"=>"test4", "name"=>"BAZ QUX", "password"=>"[FILTERED]", "email"=>"test5@plos.org"}
Completed 200 OK in 226ms (Views: 0.2ms | ActiveRecord: 44.8ms)
Sent mail to test5@plos.org (369.1ms)
Can't reach '/plugins/discourse-narrative-bot/images/font-awesome-ellipsis.png' to get its dimension.
Can't reach '/plugins/discourse-narrative-bot/images/font-awesome-bookmark.png' to get its dimension.
Started POST "/users.json" for 13.108.254.8 at 2019-02-07 18:24:47 +0000
Processing by UsersController#create as JSON
  Parameters: {"username"=>"dev1-742", "email"=>"dev1@plos.org", "name"=>"PLOS Test", "password"=>"[FILTERED]", "api_key"=>"[FILTERED]", "api_username"=>"system", "user"=>{"username"=>"dev1-742", "name"=>"PLOS Test"}}
Filter chain halted as :respond_to_suspicious_request rendered or redirected
Completed 200 OK in 2ms (Views: 0.3ms)

The first call is the successful ruby call, the second its the failing salesforce call. The only weird difference I can see is Rails nesting some of the controller’s model’s params. Any thoughts?


(Benjamin Miller) #2

Okay, I solved it. The httparty gem was defaulting to url form encoded content type while salesforce was using json, it works now that i’ve updated the script.