Really stuck on this one and pulling my hair out trying to figure out what to do, searched everywhere and tried everything but still stuck. Any help is much appreciated.
If you are using PHP try this (otherwise try converting it to whatever language you are using)
Call the below function on your mime message before setting it to the raw property.
private function base64url_encode($mime) { return rtrim(strtr(base64_encode($mime), '+/', '-_'), '='); }