gate-sso / gate

Gate is MFA Enabled SSO Platform that supports SAML, OAuth, Linux shell login and CAS
https://gate-sso.github.io
MIT License
203 stars 53 forks source link

oAuth failing - NoMethodError in Users::OmniauthCallbacksController#google_oauth2 - request.env['omniauth.auth'] #193

Closed DrIanGregory closed 2 years ago

DrIanGregory commented 2 years ago

oAuth fails to obtain credentials.

Installed gate-sso in Ubuntu location /opt/gate. Running on port 82 and reverse proxy to 80. In .env: GATE_SERVER_URL=http://gate.orthogonal.trading/

Setup Google API keys.

Click on Single Sign on. Then when clicking on the Google email account to login with. gate-sso crashes with the error: "NoMethodError in Users::OmniauthCallbacksController#google_oauth2" "undefined method `[]' for nil:NilClass"

In file: app/controllers/users/omniauth_callbacks_controller.rb:7:in `google_oauth2'. The code lines causing the issue:

data = request.env['omniauth.auth'] domain = data['info']['email'].split('@').last

These are the parameters sent in the request:

Parameters:

{"state"=>"83d21c734d8daf7647a742553453067fc4c8d47b8fd1daf9", "code"=>"4/0AX4XfWhZWa6BTZxezs0M8UT-CIn2JEwDamE45JOD7T1ggkYVCAJR4V0ezeg9MoO5Z2XIzg", "scope"=>"email profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid", "authuser"=>"1", "hd"=>"orthogonal.trading", "prompt"=>"consent"}

Response Headers: None

DrIanGregory commented 2 years ago

Issue resolved by editing .env many times: https://github.com/gate-sso/gate/blob/master/.env.example

And reading this many many times: https://github.com/gate-sso/gate/blob/master/docs/oauth_setup.md

And running the following many many times:

sudo lsof -i -P -n | grep LISTEN sudo kill -9 rake app:setup rvmsudo rails server --port 82 --binding 0.0.0.0 --daemon