Synopsis
Ruby TeleAuth Module.
Allows for two-factor authentication within Ruby. Uses the TeleAuth service.
Author
Mohit Muthanna Cheppudira <mohit AT muthanna DOTcom>
Copyright
Copyright © 2005 Mohit Muthanna Cheppudira. Licensed under the GPL.
Prerequisites
To use this module, you will need a TeleAuth API Key. Get yours at [www.teleauth.com].
Basic Usage
The following example calls a user on a specific phone number and requests a PIN code.
require 'teleauth'
conn = TeleAuth::Client.new (
'urls' = ['http://teleauth.com/api/auth'],
'domain_id' = 'mydomain',
'login' = 'dialer',
'password' = 'bu4ger'
)
Register a user’s phone number.
conn.register_phone(
'ext_uid' => 'foobar',
'phone' => '12332445443'
)
Call user and request PIN code.
conn.get_secret( 'ext_uid' => 'foobar' ) { |response|
puts "PIN code: #{ response['secret'] }"
}
TeleAuth API
In brief, you can use any API command as a TeleAuth::Client method. Arguments are provided as hash parameters. Responses are returned as Ruby hashes.
Examples:
response = conn.validate_user
conn.validate_user { |response|
# do something
}
Register a user’s phone number and PIN code.
conn.register_phone(
'ext_uid' => 'foobar',
'phone' => '12332445443',
'pin' => '45334',
)
Call the user and validate PIN
conn.validate_phone( 'ext_uid' => 'foobar' ) { |response|
if response['login'] == 'PASS'
puts "Valid PIN code."
else
puts "Authorization failed"
end
end
For the TeleAuth API reference, visit teleauth.com
Logging, Exceptions and Errors
The class raises the TeleAuth::APIError exception if the API command failed.
If you have multiple URLs, eg. for failover, the module can inform you if a failover took place.
conn.on_command_fail { |url|
puts "Failed to connect to #{ url }. Trying next one."
}
If you need nice debug output, use on_log:
con.on_log { |msg|
$stderr.puts( "LOG: #{ msg }" )
end
Support
Get on the TeleAuth Mailing List