Class: OmniAuth::Strategies::Webmoney

Inherits:
Object
  • Object
show all
Includes:
OmniAuth::Strategy
Defined in:
lib/oa-webmoney/webmoney.rb

Defined Under Namespace

Classes: WmLib

Constant Summary collapse

ERROR_MESSAGES =
{
  # -3 unknown response
  :server_not_available => "Unknown response",
  # -2 raised network error
  :server_not_available => "Sorry, the Webmoney Login server is not available",
  # -1
  :internal_error       => "Webmoney Login server internal error",
  # 1
  :invalid_arguments    => "Invalid arguments",
  # 2
  :ticket_invalid       => "Sorry, invalid authorization ticket",
  # 3
  :ticket_expired       => "Sorry, authorization ticket expired",
  # 4
  :user_not_found       => "Sorry, user not found",
  # 5
  :holder_not_found     => "The holder of a site not found",
  # 6
  :website_not_found    => "Website Not Found",
  # 7
  :url_not_found        => "This url is not found, or does not belong to the site",
  # 8
  :settings_not_found   => "Security Settings for the site could not be found",
  # 9
  :invalid_password     => "Access service is not authorized. Invalid password.",
  # 10
  :not_trusted          => "Attempting to gain access to the site, which does not accept you as a trustee",
  # 11
  :pwd_access_blocked   => "Password access to the service blocked",
  # 12
  :user_blocked         => "The user is temporarily blocked. Probably made the selection Ticket"
}

Instance Method Summary collapse

Instance Method Details

#callback_phaseObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/oa-webmoney/webmoney.rb', line 58

def callback_phase
  return cancel_authentication! if cancel_authentication?

  check_req_params = extra.merge({:remote_ip => extra[:WmLogin_UserAddress]})

  options[:wm_instance] ||= WmLib.new(:wmid => options[:credentials][:site_holder_wmid])

  begin
    response = options[:wm_instance].request(:login, check_req_params)[:retval]
  rescue Errno::ECONNRESET, Errno::ECONNREFUSED, Timeout::Error => e
    response = -2
  rescue ::Webmoney::ResultError => e
    response = options[:wm_instance].error
  end

  status = case response
  when 0  then :successful
  when -3  then :unknown_response
  when -2  then :server_not_available
  when -1  then :internal_error
  when 1   then :invalid_arguments
  when 2   then :ticket_invalid
  when 3   then :ticket_expired
  when 4   then :user_not_found
  when 5   then :holder_not_found
  when 6   then :website_not_found
  when 7   then :url_not_found
  when 8   then :settings_not_found
  when 9   then :invalid_password
  when 10  then :not_trusted
  when 11  then :pwd_access_blocked
  when 12  then :user_blocked
  when 201 then :ip_differs
  end

  return fail!(status, OmniAuth::Error.new(ERROR_MESSAGES[status])) unless status == :successful

  super
end

#cancel_authentication!Object



98
99
100
101
102
# File 'lib/oa-webmoney/webmoney.rb', line 98

def cancel_authentication!
  r = Rack::Response.new
  r.redirect "/"
  r.finish
end

#cancel_authentication?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/oa-webmoney/webmoney.rb', line 104

def cancel_authentication?
  %w(Canceled LoggedOff).include?(request.params["WmLogin_KeeperRetStr"])
end

#extraObject



112
113
114
115
116
117
# File 'lib/oa-webmoney/webmoney.rb', line 112

def extra
  options.fields.inject({}) do |hash, field|
    hash[field] = request.params[field.to_s]
    hash
  end
end

#request_phaseObject



52
53
54
55
56
# File 'lib/oa-webmoney/webmoney.rb', line 52

def request_phase
  r = Rack::Response.new
  r.redirect "https://login.wmtransfer.com/GateKeeper.aspx?RID=#{options[:credentials][:app_rids][request.host]}"
  r.finish
end

#uidObject



108
109
110
# File 'lib/oa-webmoney/webmoney.rb', line 108

def uid
  extra[:WmLogin_WMID]
end