Divide the length of the input string by 4, take the remainder. If it is 2, add two =
characters at the end. If it is 3, add one =
character at the end.
You now have Base64-URL with padding.
Replace all -
characters by +
and all _
characters by /
.
You now have Base64 with padding.
Base64 decoding should be available as a library for your favorite language...
https://github.com/Moodstocks/moodstocks-api-clients/blob/master/bash/base64url.sh