lib/utils/preauth.js
function (options, callback) {

        LOG.debug('preauth#createPreauth called');
        LOG.debug('Validating options');

        try {

            options = new preauthOptions.CreatePreauth().validate(options);

        } catch (err) {

            if (err.name === 'InvalidOption') {

                LOG.error('Invalid options specified: %s', err.message);

                callback(
                    commonErrors.InvalidOption(
                        undefined,
                        {
                            message: err.message
                        }
                    )
                );

            } else {

                LOG.error('System error: %s', err.message);

                callback(
                    commonErrors.SystemError(
                        undefined,
                        {
                            message: err.message
                        }
                    )
                );

            }

            return;

        }

        var timestamp = options.timestamp;

        if (!timestamp) {

            timestamp = new Date().getTime();

        }

        LOG.debug('Generating preauth key');

        var pakCreator = crypto.createHmac('sha1', options.key)
            .setEncoding('hex');

        pakCreator.write(
            util.format(
                '%s|%s|%s|%s',
                options.byValue,
                options.by,
                options.expires,
                timestamp
            )
        );
        pakCreator.end();
        var pak = pakCreator.read();

        LOG.debug('Returning preauth key %s', pak);

        callback(null, pak);

    }
function (options, callback) {

        LOG.debug('preauth#createPreauth called');
        LOG.debug('Validating options');

        try {

            options = new preauthOptions.CreatePreauth().validate(options);

        } catch (err) {

            if (err.name === 'InvalidOption') {

                LOG.error('Invalid options specified: %s', err.message);

                callback(
                    commonErrors.InvalidOption(
                        undefined,
                        {
                            message: err.message
                        }
                    )
                );

            } else {

                LOG.error('System error: %s', err.message);

                callback(
                    commonErrors.SystemError(
                        undefined,
                        {
                            message: err.message
                        }
                    )
                );

            }

            return;

        }

        var timestamp = options.timestamp;

        if (!timestamp) {

            timestamp = new Date().getTime();

        }

        LOG.debug('Generating preauth key');

        var pakCreator = crypto.createHmac('sha1', options.key)
            .setEncoding('hex');

        pakCreator.write(
            util.format(
                '%s|%s|%s|%s',
                options.byValue,
                options.by,
                options.expires,
                timestamp
            )
        );
        pakCreator.end();
        var pak = pakCreator.read();

        LOG.debug('Returning preauth key %s', pak);

        callback(null, pak);

    }
function ( options , callback ) { LOG . debug ( 'preauth#createPreauth called' ) ; LOG . debug ( 'Validating options' ) ; try { options = new preauthOptions . CreatePreauth ( ) . validate ( options ) ; } catch ( err ) { if ( err . name === 'InvalidOption' ) { LOG . error ( 'Invalid options specified: %s' , err . message ) ; callback ( commonErrors . InvalidOption ( undefined , { message : err . message } ) ) ; } else { LOG . error ( 'System error: %s' , err . message ) ; callback ( commonErrors . SystemError ( undefined , { message : err . message } ) ) ; } return ; } var timestamp = options . timestamp ; if ( ! timestamp ) { timestamp = new Date ( ) . getTime ( ) ; } LOG . debug ( 'Generating preauth key' ) ; var pakCreator = crypto . createHmac ( 'sha1' , options . key ) . setEncoding ( 'hex' ) ; pakCreator . write ( util . format ( '%s|%s|%s|%s' , options . byValue , options . by , options . expires , timestamp ) ) ; pakCreator . end ( ) ; var pak = pakCreator . read ( ) ; LOG . debug ( 'Returning preauth key %s' , pak ) ; callback ( null , pak ) ; }
Create a preauth value

@param {CreatePreauthOptions} options options for createPreauth
@param {callback} callback run with optional error (see throws) and
preauth key
@throws {InvalidOptionError}
@throws {SystemError}
Create a preauth value