How to use the base64urlDecode function from hoek

Find comprehensive JavaScript hoek.base64urlDecode code examples handpicked from public code repositorys.

hoek.base64urlDecode is a function that decodes a base64url encoded string.

358
359
360
361
362
363
364
365
366
    return callback(Boom.badRequest('Multiple authentications'));
}

// Parse bewit

var bewitString = Hoek.base64urlDecode(resource[3]);
if (bewitString instanceof Error) {
    return callback(Boom.badRequest('Invalid bewit encoding'));
}
fork icon1
star icon0
watch icon1

360
361
362
363
364
365
366
367
368
    return callback(Boom.badRequest('Multiple authentications'));
}

// Parse bewit

const bewitString = Hoek.base64urlDecode(resource[3]);
if (bewitString instanceof Error) {
    return callback(Boom.badRequest('Invalid bewit encoding'));
}
fork icon0
star icon0
watch icon1

How does hoek.base64urlDecode work?

hoek.base64urlDecode is a function that decodes a base64url-encoded string to its original form by converting any URL-safe base64url characters back to their original base64 representation and padding the string with "=" characters to ensure it is properly formatted.

Ai Example

1
2
3
4
5
6
const Hoek = require("@hapi/hoek");

const encoded = "aGVsbG8gd29ybGQ";
const decoded = Hoek.base64urlDecode(encoded);

console.log(decoded.toString()); // Output: "hello world"

In the above example, hoek.base64urlDecode() function decodes the base64url encoded string "aGVsbG8gd29ybGQ" to "hello world" using the toString() method of the decoded buffer.