Checks the token is V1 Returns the token type 1 = V1 2 = V2 or unknown
(token string)
| 354 | // 1 = V1 |
| 355 | // 2 = V2 or unknown |
| 356 | func CheckTokenType(token string) int { |
| 357 | // Check if this is a V1 token instead of a V2 (JWT) |
| 358 | // We can do this by checking if the second segment is a base64 UUID |
| 359 | splitToken := strings.Split(token, ".") |
| 360 | if len(splitToken) == 3 { |
| 361 | possibleUUID, err := cryption.Base64URLDecode(splitToken[1]) |
| 362 | |
| 363 | if err != nil { |
| 364 | return 2 |
| 365 | } |
| 366 | |
| 367 | // Check if possibleUUID is a UUID v4 |
| 368 | _, err = uuid.Parse(possibleUUID) |
| 369 | if err == nil { |
| 370 | return 1 |
| 371 | } |
| 372 | } |
| 373 | return 2 |
| 374 | } |
| 375 | |
| 376 | // This function converts the legacy V1 token format into a valid V2 token. |
| 377 | // This is used for backwards compatibility with the old V1 tokens. |
no test coverage detected