Automattic\WooCommerce\StoreApi\Utilities

JsonWebToken::from_base_64_url()private staticWC 1.0

Decodes a string encoded using url safe base64, supporting auto padding.

Method of the class: JsonWebToken{}

No Hooks.

Return

String.

Usage

$result = JsonWebToken::from_base_64_url( $string );
$string(string) (required)
the string to be decoded.

JsonWebToken::from_base_64_url() code WC 8.6.1

private static function from_base_64_url( string $string ) {
	/**
	 * Add padding to base64 strings which require it. Some base64 URL strings
	 * which are decoded will have missing padding which is represented by the
	 * equals sign.
	 */
	if ( strlen( $string ) % 4 !== 0 ) {
		return self::from_base_64_url( $string . '=' );
	}

	return base64_decode( // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_decode
		str_replace(
			array( '-', '_' ),
			array( '+', '/' ),
			$string
		)
	);
}