MCPcopy Create free account
hub / github.com/Preloading/TwitterAPIBridge / ConvertV1TokenToV2

Function ConvertV1TokenToV2

twitterv1/auth.go:378–415  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
378func 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

Callers 1

GetAuthFromReqFunction · 0.85

Calls 1

Base64URLDecodeFunction · 0.92

Tested by

no test coverage detected