google-authenticator icon indicating copy to clipboard operation
google-authenticator copied to clipboard

Adding the gem to the project changes the Content-Type of http response to my GraphQL API

Open jivea opened this issue 2 years ago • 2 comments

Hello, First of all, thank you for this very usefull and time saving gem. Thanks to it, I could integrate MFA with Authenticar apps.

However, when deploying the feature to the testing environement, it appeared to break the JSON API of the project. I could more or less isolate the problem that I can describe like this:

  • Beside the usual web application, my Ruby on rails project runs an http API that inherits from ActionController::API.

  • Simply adding the gem to the Gemfile changes the behaviour of this API: the Content-Type header of the response is set to 'text/plain' instead of 'application/json' and the returned data is empty. This causes api clients to break.

  • If I comment the following lines of the gem, the Content-Type header is back to 'application/json', the data is OK and the API is fixed. lib/google-authenticator-rails/action_controller/rails_adapter.rb, lines 44 ->46

if defined?(ActionController::API) ActionController::API.send(:include, GoogleAuthenticatorRails::ActionController::Integration) end

I am pretty novice to Ruby on Rails and I have to admit that I don't understand much of what's going under all this.

Do you have an idea of how I could fix or workaround the problem ?

jivea avatar Oct 31 '23 14:10 jivea

Hi @jaredonline, any thoughts on this topic? What if I submit a pull request that adds a setting "Apply on API" ? Any chance to get it merged?

jivea avatar Nov 24 '23 11:11 jivea

Heya @jivea sorry I've been slow to respond - I don't spend a lot of time on this project anymore.

I'm not really sure why adding the gem would change the response type of your API responses... I haven't encountered that before and there isn't anything in the project that should do that.

What version of Rails/Ruby/Bundler are you using? What other gems are in your gemfile?

jaredonline avatar Dec 04 '23 18:12 jaredonline