MyPW Developer Resources

MyPW Example: Perl


This example is based on the XMLRPC::Lite and Digest::SHA modules.

Sample Code
 
#!/usr/bin/perl

use XMLRPC::Lite;
use Digest::SHA qw(sha512_base64);

# This is the secret that was giving to you at signup, aslo available on your profile page.
$secret = 'mypwsecret';

# This is your mypw login to access the MyPW site.
$siteid = 'mypwlogin';

# This is your authkey that was giving to you at signup, aslo available on your profile page.
$authkey = 'mypwauthkey';

# This is an option field to store the IP Address of the user who used the MyPW Token
$userip = $ENV{REMOTE_ADDR};

# This is an optional field sitename which may be used for example for accounting purposes of subaccounts.
$sitename = 'seattle';

# This is an optional note field which can be used for example to describe at which point the MyPW token was used within the site or program.
$note = 'user login';

# Acquire tokenid, and tokenvalue here
# Make the call to MyPW
my $result = XMLRPC::Lite
->proxy('https://services.mypw.com/RPC2')
->call('auth.auth', 
	{
	siteid => XMLRPC::Data->type('string', $siteid), 
	authkey => XMLRPC::Data->type('string', $authkey), 
	tokenid => XMLRPC::Data->type('string', $tokenid), 
	tokenvalue => XMLRPC::Data->type('string', $tokenvalue),
	userip => XMLRPC::Data->type('string', $userip),
	sitename => XMLRPC::Data->type('string', $sitename),
        note => XMLRPC::Data->type('string', $note)
	}
)
->result;
# Prepare local string for message digest
$valdata = "$secret$tokenid$tokenvalue$authkey";

# Perform sha512_bas64 message digest on string.
$validate = sha512_base64($valdata);

# The response is stored in the result hash
print "Result: $result->{code} -- $result->{message}\n";

# The Local Validate and the Response Validate must be the same
print "Local Validate: $validate -- Response Validate: $result->{validate}\n";
if ($validate eq $result->{validate}) { print "Valid Response\n" } else { print "Invalid Response\n" }

 
Google Groups Beta
Subscribe to MyPW Developers
Email:
Visit this group
Have you created a bit of code that might be of interest to other MyPW developers? Post it on MyPW google groups.