1

当用户选择取消使用linkedin登录我的应用程序时,我该如何处理?

当我点击取消时,我被重定向到以下 URL:localhost:9393/auth/linkedin/callback?oauth_problem=user_refused

显示以下错误消息:OAuth::Problem at /auth/linkedin/callback parameter_absent

如果他们选择取消使用 Linkedin 登录,我只想将用户重定向到主页。

# ************************************************
# Oauth using Omniauth methods
# ************************************************

%w(get post).each do |method|
    send(method, "/auth/:provider/callback") do
        "<pre>" + env['omniauth.auth'].inspect + "</pre>"
    end
end


ENV['LINKEDIN_CONSUMER_KEY'] = "xxxxxxx"
ENV['LINKEDIN_CONSUMER_SECRET'] = "xxxxxxxx"

use OmniAuth::Builder do
    provider :linkedin, ENV['LINKEDIN_CONSUMER_KEY'], ENV['LINKEDIN_CONSUMER_SECRET'], :scope => 'r_fullprofile+r_emailaddress+r_network', :fields => ["id", "email-address", "first-name", "last-name", "headline", "industry", "picture-url", "public-profile-url", "location", "connections"]

end

get '/auth/failure' do
    flash[:notice] = params[:message] # if using sinatra-flash or rack-flash
    redirect '/'
end
4

1 回答 1

0

在 Rails 应用程序上,我通过将以下内容放入我的 config/initializers/omniauth.rb 解决了同样的问题。请注意,我重定向到验证失败的特定路由,以便我可以提供一些有关使用 Linkedin 登录的提示:

OmniAuth.config.on_failure do |env|
    message_key = env['omniauth.error.type']
    origin_query_param = env['omniauth.origin'] ? "&origin=#{CGI.escape(env['omniauth.origin'])}" : ""
    strategy_name_query_param = env['omniauth.error.strategy'] ? "&strategy=#{env['omniauth.error.strategy'].name}" : ""
    extra_params = env['omniauth.params'] ? "&#{env['omniauth.params'].to_query}" : ""
    new_path = "/auth_failure?message=#{message_key}#{origin_query_param}#{strategy_name_query_param}#{extra_params}"
    Rack::Response.new(["302 Moved"], 302, 'Location' => new_path).finish
end

在这里找到更多信息: 如何拯救 OmniAuth::Strategies::OAuth2::CallbackError?

于 2013-07-09T19:44:29.123 回答