尝试使用JWT开发我的应用程序的访问控制,我正在遵循我在社区中找到的一些建议,我正在编码和解码令牌部分,通过服务器端的这两个函数(PHP Restfull API):
textContent
但是从客户端(Angular2),我无法对其进行解码并收到以下错误消息:
static function base64Url_encode( $val ){
return strtr(base64_encode( $val ), '+/=', '-_,');
}
static function base64Url_decode( $val ){
return base64_decode( strtr($val , '+/=', '-_,') );
}
经过社区搜索后,我决定这样做:
Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
它工作正常,但我确信有更好的方法。
解码返回的字符串是否有比嵌套替换函数更好的解决方案?