https://developer.x.com/en/docs/authentication/api-reference/access_token and https://web.archive.org/web/20120708225149/https://dev.twitter.com/docs/oauth/xauth
(c *fiber.Ctx)
| 22 | // and |
| 23 | // https://web.archive.org/web/20120708225149/https://dev.twitter.com/docs/oauth/xauth |
| 24 | func access_token(c *fiber.Ctx) error { |
| 25 | // Parse the form data |
| 26 | //sendErrorCodes := c.FormValue("send_error_codes") |
| 27 | authMode := c.FormValue("x_auth_mode") |
| 28 | authPassword := c.FormValue("x_auth_password") |
| 29 | authUsername := c.FormValue("x_auth_username") |
| 30 | |
| 31 | if authMode == "client_auth" { |
| 32 | res, pds, err := blueskyapi.Authenticate(authUsername, authPassword) |
| 33 | if err != nil { |
| 34 | return HandleBlueskyError(c, err.Error(), "com.atproto.server.createSession", access_token) |
| 35 | } |
| 36 | |
| 37 | // Our bluesky authentication was sucessful! Now we should store the auth info, encryted, in the DB |
| 38 | encryptionkey, err := cryption.GenerateKey() |
| 39 | if err != nil { |
| 40 | fmt.Println("Error:", err) |
| 41 | return ReturnError(c, "Failed to generate encryption key", 131, fiber.StatusInternalServerError) |
| 42 | } |
| 43 | |
| 44 | access_token_expiry, err := cryption.GetJWTTokenExpirationUnix(res.AccessJwt) |
| 45 | if err != nil { |
| 46 | fmt.Println("Error:", err) |
| 47 | return ReturnError(c, "Failed to get token expiration.", 131, fiber.StatusInternalServerError) |
| 48 | } |
| 49 | refresh_token_expiry, err := cryption.GetJWTTokenExpirationUnix(res.RefreshJwt) |
| 50 | if err != nil { |
| 51 | fmt.Println("Error:", err) |
| 52 | return ReturnError(c, "Failed to get token expiration.", 131, fiber.StatusInternalServerError) |
| 53 | } |
| 54 | |
| 55 | uuid, err := db_controller.StoreToken(res.DID, *pds, res.AccessJwt, res.RefreshJwt, encryptionkey, *access_token_expiry, *refresh_token_expiry) |
| 56 | |
| 57 | if err != nil { |
| 58 | fmt.Println("Error:", err) |
| 59 | return ReturnError(c, "Failed to store token, if this persists contact instance operator.", 131, fiber.StatusInternalServerError) |
| 60 | } |
| 61 | encryptionkey = strings.ReplaceAll(encryptionkey, "+", "-") |
| 62 | encryptionkey = strings.ReplaceAll(encryptionkey, "/", "_") |
| 63 | encryptionkey = strings.ReplaceAll(encryptionkey, "=", "") // remove padding |
| 64 | |
| 65 | token := jwt.NewWithClaims(jwt.SigningMethodHS256, bridge.AuthToken{ |
| 66 | Version: 2, |
| 67 | Platform: "bluesky", |
| 68 | DID: res.DID, |
| 69 | CryptoKey: encryptionkey, |
| 70 | TokenUUID: *uuid, |
| 71 | ServerIdentifier: configData.ServerIdentifier, |
| 72 | ServerURLs: configData.ServerURLs, |
| 73 | RegisteredClaims: &jwt.RegisteredClaims{ |
| 74 | // No ExpiresAt field means the token never expires |
| 75 | IssuedAt: jwt.NewNumericDate(time.Now()), |
| 76 | NotBefore: jwt.NewNumericDate(time.Now()), |
| 77 | Issuer: configData.ServerIdentifier, |
| 78 | ExpiresAt: jwt.NewNumericDate(time.Date(9999, 1, 1, 0, 0, 0, 0, time.UTC)), // it dies without this. i guess it's also nice to have ig |
| 79 | }, |
| 80 | }) |
| 81 |
nothing calls this directly
no test coverage detected