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

Function DeleteTokenViaBasic

db_controller/db_controller.go:329–363  ·  view source on GitHub ↗

DeleteTokenViaBasic deletes a token using the username and password

(username string, password string)

Source from the content-addressed store, hash-verified

327
328// DeleteTokenViaBasic deletes a token using the username and password
329func DeleteTokenViaBasic(username string, password string) error {
330 var tokens []Token
331 if err := db.Where("basic_auth_username = ?", username).Find(&tokens).Error; err != nil {
332 return fmt.Errorf("invalid credentials")
333 }
334
335 if len(tokens) == 0 {
336 return fmt.Errorf("token not found")
337 }
338
339 var foundToken Token
340 for _, t := range tokens {
341 if err := bcrypt.CompareHashAndPassword([]byte(t.BasicAuthHash), []byte(password)); err != nil {
342 foundToken = t
343 break
344 }
345 }
346
347 if foundToken.EncryptedAccessToken == "" {
348 return fmt.Errorf("invalid credentials")
349 }
350
351 result := db.Where("basic_auth_username = ? AND basic_auth_hash = ?",
352 username, foundToken.BasicAuthHash).Delete(&Token{})
353
354 if result.Error != nil {
355 return result.Error
356 }
357
358 if result.RowsAffected == 0 {
359 return fmt.Errorf("token not found")
360 }
361
362 return nil
363}
364
365// Stores ID data in the database.
366// @params: twitterID, blueskyID, dateCreated, reposterDid

Callers 1

GetAuthFromReqFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected