Merged createJwt method from 6043c9329798cd12159aa3b019797d6ecf04c5c3