14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'app/controllers/standard_id/web/auth/callback/providers_controller.rb', line 14
def callback
if params[:error].present?
handle_callback_error
return
end
state_data = nil
begin
state_data = decode_state_params
redirect_uri = callback_url_for
provider_response = get_user_info_from_provider(redirect_uri: redirect_uri)
social_info = provider_response[:user_info]
provider_tokens = provider_response[:tokens]
account = find_or_create_account_from_social(social_info)
session_manager.sign_in_account(account)
run_social_callback(
provider: provider.provider_name,
social_info: social_info,
provider_tokens: provider_tokens,
account: account,
)
destination = state_data["redirect_uri"]
redirect_options = { notice: "Successfully signed in with #{provider.provider_name.humanize}" }
redirect_options[:allow_other_host] = true if allow_other_host_redirect?(destination)
redirect_to destination, redirect_options
rescue StandardId::OAuthError => e
redirect_to StandardId::WebEngine.routes.url_helpers.login_path(redirect_uri: state_data&.dig("redirect_uri")), alert: "Authentication failed: #{e.message}"
end
end
|