| 329 | } |
| 330 | |
| 331 | func GetEncryptionKeyFromRequest(c *fiber.Ctx) (*string, error) { |
| 332 | authHeader := c.Get("Authorization") |
| 333 | // Define a regular expression to match the oauth_token |
| 334 | re := regexp.MustCompile(`oauth_token="([^"]+)"`) |
| 335 | matches := re.FindStringSubmatch(authHeader) |
| 336 | |
| 337 | if len(matches) < 2 { |
| 338 | return nil, errors.New("oauth token not found") |
| 339 | } |
| 340 | |
| 341 | oauthToken := matches[1] |
| 342 | oauthTokenSegments := strings.Split(oauthToken, ".") |
| 343 | |
| 344 | // Get the encryption key for the data. |
| 345 | encryptionKey := oauthTokenSegments[2] + "=" |
| 346 | encryptionKey = strings.ReplaceAll(encryptionKey, "-", "+") |
| 347 | encryptionKey = strings.ReplaceAll(encryptionKey, "_", "/") |
| 348 | |
| 349 | return &encryptionKey, nil |
| 350 | } |
| 351 | |
| 352 | // Checks the token is V1 |
| 353 | // Returns the token type |