base64URLDecode decodes a Base64 URL-encoded string, adding padding if necessary. JWTs use a URL-safe Base64 alphabet and omit padding, so this function ensures correct decoding by re-adding the padding before decoding.
(data string)
| 79 | // JWTs use a URL-safe Base64 alphabet and omit padding, so this function ensures |
| 80 | // correct decoding by re-adding the padding before decoding. |
| 81 | func base64URLDecode(data string) ([]byte, error) { |
| 82 | // Add padding if necessary |
| 83 | switch len(data) % 4 { |
| 84 | case 2: |
| 85 | data += "==" |
| 86 | case 3: |
| 87 | data += "=" |
| 88 | } |
| 89 | |
| 90 | return base64.URLEncoding.DecodeString(data) |
| 91 | } |
| 92 | |
| 93 | // GetUserEmail extracts the user's email address from the JWT claims. |
| 94 | func (c *JWTClaims) GetUserEmail() string { |