MCPcopy Index your code
hub / github.com/Preloading/TwitterAPIBridge / UpdateTokenBasic

Function UpdateTokenBasic

db_controller/db_controller.go:224–254  ·  view source on GitHub ↗

UpdateTokenBasic updates or creates a token entry using basic auth

(did string, pds string, accessToken string, refreshToken string, accessExpiry float64, refreshExpiry float64, username string, password string, passwordHash string, passwordSalt string, uuid string)

Source from the content-addressed store, hash-verified

222
223// UpdateTokenBasic updates or creates a token entry using basic auth
224func UpdateTokenBasic(did string, pds string, accessToken string, refreshToken string, accessExpiry float64, refreshExpiry float64, username string, password string, passwordHash string, passwordSalt string, uuid string) (*string, error) {
225 encryptionKey := authcrypt.DeriveKeyFromPassword(password, passwordSalt)
226 encryptedAccess, err := authcrypt.Encrypt(accessToken, encryptionKey)
227 if err != nil {
228 return nil, fmt.Errorf("failed to encrypt access token: %v", err)
229 }
230
231 encryptedRefresh, err := authcrypt.Encrypt(refreshToken, encryptionKey)
232 if err != nil {
233 return nil, fmt.Errorf("failed to encrypt refresh token: %v", err)
234 }
235
236 token := Token{
237 UserDid: did,
238 UserPDS: pds,
239 EncryptedAccessToken: encryptedAccess,
240 EncryptedRefreshToken: encryptedRefresh,
241 AccessExpiry: accessExpiry,
242 RefreshExpiry: refreshExpiry,
243 BasicAuthHash: passwordHash,
244 BasicAuthSalt: passwordSalt,
245 BasicAuthUsername: username,
246 TokenUUID: uuid,
247 }
248
249 if err := db.Create(&token).Error; err != nil {
250 return nil, err
251 }
252
253 return &token.TokenUUID, nil
254}
255
256// GetToken retrieves account data from the database
257// @results: accessToken, refreshToken, accessExpiry, refreshExpiry, pds, error

Callers 2

GetAuthFromReqFunction · 0.92
StoreTokenBasicFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected