class Sezame::Client
base class for client requests.
Attributes
http[R]
Public Class Methods
new(cert = nil, key = nil, keypassword = nil)
click to toggle source
Expects a certificate string in pem format, the corresponding private key and an optional keypassword
# File lib/sezame-sdk/client.rb, line 15 def initialize(cert = nil, key = nil, keypassword = nil) @http = SezameJSONClient.new @http.connect_timeout = 10 @endpoint = 'https://hqfrontend-finprin.finprin.com/' if cert != nil && key != nil @http.ssl_config.client_cert = OpenSSL::X509::Certificate.new(cert) @http.ssl_config.client_key = OpenSSL::PKey.read(key, keypassword) end end
Public Instance Methods
fraud(username, message = nil, timeout = nil, callback = nil, extra_params = nil)
click to toggle source
inform the user about fraud attempts, like plaintext password logins
# File lib/sezame-sdk/client.rb, line 137 def fraud(username, message = nil, timeout = nil, callback = nil, extra_params = nil) authorize(username, message, timeout, 'fraud', callback, extra_params) end
link(username)
click to toggle source
pair the given username with your application
# File lib/sezame-sdk/client.rb, line 96 def link(username) endpoint = @endpoint + 'client/link' response = @http.post endpoint, { :username => username } ret = Sezame::Response::Link.new(response) ret.username = username ret end
link_delete(username)
click to toggle source
remove the pairing for the given username
# File lib/sezame-sdk/client.rb, line 107 def link_delete(username) endpoint = @endpoint + 'client/link' response = @http.delete endpoint, { :username => username } Sezame::Response::LinkDelete.new(response) end
link_status(username)
click to toggle source
check the pairing status for the given username
# File lib/sezame-sdk/client.rb, line 87 def link_status(username) endpoint = @endpoint + 'client/link/status' response = @http.post endpoint, { :username => username } response.content end
makecsr(clientcode, email, x509 = {}, keylen = 2048)
click to toggle source
helper function for building a csr pass the client code, obtained by the registration call add an e-mail address and additional x509 options
# File lib/sezame-sdk/client.rb, line 42 def makecsr(clientcode, email, x509 = {}, keylen = 2048) options = { :country => 'AT', :state => 'Vienna', :city => 'Vienna', :organization => '-', :department => '-', :common_name => clientcode, :email => email } options.merge!(x509) key = OpenSSL::PKey::RSA.new(keylen) csr = OpenSSL::X509::Request.new csr.version = 0 csr.subject = OpenSSL::X509::Name.new([ ['C', options[:country], OpenSSL::ASN1::PRINTABLESTRING], ['ST', options[:state], OpenSSL::ASN1::PRINTABLESTRING], ['L', options[:city], OpenSSL::ASN1::PRINTABLESTRING], ['O', options[:organization], OpenSSL::ASN1::UTF8STRING], ['OU', options[:department], OpenSSL::ASN1::UTF8STRING], ['CN', options[:common_name], OpenSSL::ASN1::UTF8STRING], ['emailAddress', options[:email], OpenSSL::ASN1::UTF8STRING] ]) csr.public_key = key.public_key csr.sign(key, OpenSSL::Digest::SHA256.new) { :csr => csr.to_pem, :key => key.to_pem } end
register(email, name)
click to toggle source
start the self-registration process by specifying a recovery e-mail entered during app installation and a name for your application
# File lib/sezame-sdk/client.rb, line 30 def register(email, name) endpoint = @endpoint + 'client/register' response = @http.post endpoint, { :email => email, :name => name } Sezame::Response::Register.new(response) end
sign(csr, sharedsecret)
click to toggle source
let the csr signed by the hq server, pass the shared secret as optained by the register call
# File lib/sezame-sdk/client.rb, line 77 def sign(csr, sharedsecret) endpoint = @endpoint + 'client/sign' response = @http.post endpoint, { :csr => csr, :sharedsecret => sharedsecret } Sezame::Response::Sign.new(response) end
status(auth_id)
click to toggle source
fetch the status of an authentication request
# File lib/sezame-sdk/client.rb, line 142 def status(auth_id) endpoint = @endpoint + 'auth/status/' + auth_id Sezame::Response::Status.new(@http.get endpoint) end