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 に答える