diff --git a/app/controllers/v1/omniauth_callbacks_controller.rb b/app/controllers/v1/omniauth_callbacks_controller.rb index c93991cc4b1aa5f25bb10a746eaf38abae75f9c5..4b322bce3c071dcc0bee7a0fbba46266a98f0093 100644 --- a/app/controllers/v1/omniauth_callbacks_controller.rb +++ b/app/controllers/v1/omniauth_callbacks_controller.rb @@ -18,34 +18,34 @@ # along with portalmec. If not, see <http://www.gnu.org/licenses/>. require 'open-uri' - class V1::OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController - - protected - - # break out provider attribute assignment for easy method extension - def assign_provider_attrs(user, auth_hash) - avatar = URI.parse(auth_hash['info']['image']).open - - user.assign_attributes({ - nickname: auth_hash['info']['nickname'], - name: auth_hash['info']['name'], - avatar: avatar, - email: auth_hash['info']['email'] - }) - end - - def gov - @user = User.from_gov_br_omniauth(request.env["omniauth.auth"]["info"]) - - if @user.id.present? - sign_in_and_redirect @user, :event => :authentication - set_flash_message(:notice, :success, :kind => "Login Unico") if is_navigational_format? - else - end - end - - def failure - redirect_to root_path - end +class V1::OmniauthCallbacksController < DeviseTokenAuth::OmniauthCallbacksController + def gov + @user = User.from_gov_br_omniauth(request.env["omniauth.auth"]["info"]) + + if @user.id.present? + sign_in_and_redirect @user, :event => :authentication + set_flash_message(:notice, :success, :kind => "Login Unico") if is_navigational_format? + else + end + end + + protected + + # break out provider attribute assignment for easy method extension + def assign_provider_attrs(user, auth_hash) + avatar = URI.parse(auth_hash['info']['image']).open + + user.assign_attributes({ + nickname: auth_hash['info']['nickname'], + name: auth_hash['info']['name'], + avatar: avatar, + email: auth_hash['info']['email'] + }) + end + + + def failure + redirect_to root_path end +end diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index d85995376986959d784ab33b82c43a486dd0dbe0..4b3acd0e4e5852120b66995419ebcfabbbebccf9 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -265,14 +265,14 @@ Devise.setup do |config| ENV['GOV_KEY'], ENV['GOV_SECRET'], scope: 'openid+email+profile+govbr_confiabilidades+', - callback_path: 'v1/auth/gov/callback', + callback_path: '/v1/auth/gov/callback', client_options: { site: 'https://sso.staging.acesso.gov.br', # Ambiente de produção. authorize_url: 'https://sso.staging.acesso.gov.br/authorize', # Ambiente de produção. token_url: 'https://sso.staging.acesso.gov.br/token' # Ambiente de produção. } - config.omniauth_path_prefix = '/prefixo-devise/prefixo-omniauth' + #config.omniauth_path_prefix = '/prefixo-devise/prefixo-omniauth' # ==> Warden configuration # If you want to use other strategies, that are not supported by Devise, or diff --git a/config/initializers/omniauth.rb b/config/initializers/omniauth.rb index d4f0470fe0fca592600c9b1624bcd1c86840237c..bc3e6508f1e78aba0f4112c7d3bf20829b3af7e7 100644 --- a/config/initializers/omniauth.rb +++ b/config/initializers/omniauth.rb @@ -17,28 +17,22 @@ # You should have received a copy of the GNU Affero General Public License # along with portalmec. If not, see <http://www.gnu.org/licenses/>. -Rails.application.config.middleware.use OmniAuth::Builder do - provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] - provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], - secure_image_url: true, - client_options: { - site: 'https://graph.facebook.com/v4.0', - authorize_url: "https://www.facebook.com/v4.0/dialog/oauth" - } - provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'] - # provider :gov_brasdf, - # ENV['GOV_KEY'], - # ENV['GOV_SECRET'], - # scope: 'openid+email+profile+govbr_confiabilidades+', - # # ACHO que isso nao precisa especificar? - # #callback_path: '/callback-da-aplicacao', - # client_options: { - # site: 'https://sso.staging.acesso.gov.br', - # authorize_url: 'https://sso.staging.acesso.gov.br/authorize', - # token_url: 'https://sso.staging.acesso.gov.br/token' - # } -end +#Rails.application.config.middleware.use OmniAuth::Builder do +# provider :twitter, ENV['TWITTER_KEY'], ENV['TWITTER_SECRET'] +# provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'], +# secure_image_url: true, +# client_options: { +# site: 'https://graph.facebook.com/v4.0', +# authorize_url: "https://www.facebook.com/v4.0/dialog/oauth" +# } +# provider :google_oauth2, ENV['GOOGLE_KEY'], ENV['GOOGLE_SECRET'] +#end OmniAuth.config.allowed_request_methods = [:post, :get] -OmniAuth.config.full_host = Rails.env.production? ? 'https://api.mecred.c3sl.ufpr.br' : 'https://api.mecred.c3sl.ufpr.br' +if Rails.env.production? + OmniAuth.config.full_host = 'https://api.mecred.c3sl.ufpr.br' +elsif Rails.env.development? + OmniAuth.config.full_host = 'https://api.mecredhomologa.c3sl.ufpr.br' +end + OmniAuth.config.logger = Rails.logger