The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


Auth::Yubikey_WebClient - Authenticating the Yubikey against the Yubico Web API


Version 4.02


Authenticate against the Yubico server via the Web API in Perl

Sample CGI script :-


        use CGI;
        use strict;

        my $cgi = new CGI;
        my $otp = $cgi->param("otp");

        print $cgi->header();
        print "<html>\n";
        print "<form method=get>Yubikey : <input type=text name=otp size=40 type=password></form>\n";

        use Auth::Yubikey_WebClient;

        my $id = "<enter your id here>";
        my $api = "<enter your API key here>";
        my $nonce = "<enter your nonce here>";

                my $result = Auth::Yubikey_WebClient::yubikey_webclient($otp,$id,$api,$nonce);
                # result can be either ERR or OK

                print "Authentication result : <b>$result</b><br>";

        print "</html>\n";



Creates a new Yubikey Webclient connection

   use Auth::Yubikey_WebClient;

   my $yubi = Auth::Yubikey_WebClient->new({
        id => <enter your id here> ,
        api => '<enter your API key here>' ,
        nonce => '<enter your nonce if you have one>',
        verify_hostname => 0    # optional - defaults to 1.  Can be set to 0 if you do not want to check the validity of the SSL certificate when querying the Yubikey server

You can overwrite the URL called if you want to call an alternate authentication server as well :-

   use Auth::Yubikey_WebClient;

   my $yubi = Auth::Yubikey_WebClient->new({
        id => <enter your id here> ,
        api => '<enter your API key here>' ,
        nonce => '<enter your nonce if you have one>',
        url => ''


Displays the debug info


Prints out some debug information. Useful to be called after authentication to see what Yubico sent back. You can also call the variables yourself, for example if you'd like to see what the token ID is, call $yubi->{publicid}. The same goes for all the other variables printed in debug.



Check a OTP for validity

        $result = $yubi->otp($otp);

Call the otp procedure with the input from the yubikey. It will return the result.

This function will also setup a few internal variables that was returned from Yubico.


Before you can use this module, you need to register for an API key at Yubico. This is as simple as logging onto <> and entering your Yubikey's OTP and your email address. Once you have the API and ID, you need to provide those details to the module to work.


Phil Massyn, <massyn at>


Please report any bugs or feature requests to bug-auth-yubikey_webclient at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Auth::Yubikey_WebClient

You can also look for information at:

Version history

0.04 - Fixed bug 1.00 - Added validation of the request to Yubico (Thanks to Kirill Miazine) 2.00 - Added nounce coding (Thanks to Ludvig af Klinteberg) 2.01 - Response turning into an array due to \r bug (Thanks to Peter Norin) 3.00 - Major update 4.01 - 13.10.2016 - Requested by Peter Norin - update to use LWP::UserAgent, and the option to overwrite a valid SSL certificate (verify_hostname). The API default server is changed to ssl. 4.02 - 2019.04.04 - Request by Alexandre Linte - Support for proxy servers



Copyright 2016 Phil Massyn, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.