]> gitweb.factorcode.org Git - factor.git/commitdiff
base64: Add a version of url-base64 that trims trailing === for jwt.
authorDoug Coleman <doug.coleman@gmail.com>
Fri, 9 Apr 2021 14:23:28 +0000 (09:23 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Fri, 9 Apr 2021 14:23:28 +0000 (09:23 -0500)
See https://tools.ietf.org/html/rfc7519
and
https://stackoverflow.com/questions/49082844/how-could-firebase-send-a-jwt-token-which-payload-contains-an-underscore-charact

basis/base64/base64-tests.factor
basis/base64/base64.factor

index 8821f9654c05c952cbef019ff65094844848ecd1..3593fe2c7d37fd6f71c22972abc738046dc54ae6 100644 (file)
@@ -47,3 +47,9 @@ kernel sequences splitting strings tools.test ;
 
 { "01a-b_cd" } [ "\xd3V\xbeo\xf7\x1d" >urlsafe-base64 "" like ] unit-test
 { "\xd3V\xbeo\xf7\x1d" } [ "01a-b_cd" urlsafe-base64> "" like ] unit-test
+
+{ "eyJhIjoiYmNkIn0" }
+[ "{\"a\":\"bcd\"}" >urlsafe-base64-jwt >string ] unit-test
+
+{ "{\"a\":\"bcd\"}" }
+[ "{\"a\":\"bcd\"}" >urlsafe-base64-jwt urlsafe-base64> >string ] unit-test
\ No newline at end of file
index e9b9b62d13c7f6e5002695276ff964a902860db2..a85768aafe76140afaf85b561e8d005c75217ff1 100644 (file)
@@ -146,6 +146,9 @@ PRIVATE>
         { CHAR: / CHAR: _ }
     } substitute ;
 
+: >urlsafe-base64-jwt ( seq -- base64 )
+    >urlsafe-base64 [ CHAR: = = ] trim-tail ;
+
 : urlsafe-base64> ( base64 -- seq )
     H{
         { CHAR: - CHAR: + }