This function converts the legacy V1 token format into a valid V2 token. This is used for backwards compatibility with the old V1 tokens.
(token string)
| 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. |
| 378 | func ConvertV1TokenToV2(token string) (*bridge.AuthToken, error) { |
| 379 | // V1 tokens aren't very secure (they can be tampered with easily) |
| 380 | |
| 381 | // Split the token into its components |
| 382 | parts := strings.Split(token, ".") |
| 383 | if len(parts) != 3 { |
| 384 | return nil, errors.New("invalid token") |
| 385 | } |
| 386 | |
| 387 | // Check that we have at least 3 segments |
| 388 | if len(parts) != 3 { |
| 389 | return nil, errors.New("invalid token") |
| 390 | } |
| 391 | |
| 392 | // Get user DID |
| 393 | userDID, err := cryption.Base64URLDecode(parts[0]) |
| 394 | |
| 395 | if err != nil { |
| 396 | return nil, errors.New("invalid token") |
| 397 | } |
| 398 | |
| 399 | // Get our token UUID. This is used to look up the token in the database. |
| 400 | tokenUUID, err := cryption.Base64URLDecode(parts[1]) |
| 401 | |
| 402 | if err != nil { |
| 403 | return nil, errors.New("invalid token") |
| 404 | } |
| 405 | |
| 406 | return &bridge.AuthToken{ |
| 407 | Version: 1, |
| 408 | Platform: "bluesky", |
| 409 | DID: userDID, |
| 410 | CryptoKey: parts[2], |
| 411 | TokenUUID: tokenUUID, |
| 412 | ServerIdentifier: configData.ServerIdentifier, |
| 413 | ServerURLs: configData.ServerURLs, |
| 414 | }, nil |
| 415 | } |
| 416 | |
| 417 | // Some stuff to avoid refreshing race conditions |
| 418 |
no test coverage detected