mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-28 06:57:56 +02:00
Custom OAuth2 TokenSource to persist refreshed tokens in database
This commit is contained in:
parent
4a9f26d9db
commit
e29d8e2a63
8 changed files with 92 additions and 39 deletions
14
cmd/loves.go
14
cmd/loves.go
|
@ -49,21 +49,11 @@ var lovesCmd = &cobra.Command{
|
|||
cobra.CheckErr(err)
|
||||
|
||||
// Authenticate backends, if needed
|
||||
token, err := db.GetOAuth2Token(sourceName)
|
||||
_, err = backends.Authenticate(sourceName, exportBackend, db, viper.GetViper())
|
||||
cobra.CheckErr(err)
|
||||
auth, err := backends.Authenticate(exportBackend, token, viper.GetViper())
|
||||
cobra.CheckErr(err)
|
||||
if auth {
|
||||
db.SetOAuth2Token(sourceName, token)
|
||||
}
|
||||
|
||||
token, err = db.GetOAuth2Token(targetName)
|
||||
_, err = backends.Authenticate(targetName, importBackend, db, viper.GetViper())
|
||||
cobra.CheckErr(err)
|
||||
auth, err = backends.Authenticate(importBackend, token, viper.GetViper())
|
||||
cobra.CheckErr(err)
|
||||
if auth {
|
||||
defer db.SetOAuth2Token(targetName, token)
|
||||
}
|
||||
|
||||
// Read timestamp
|
||||
timestamp := time.Unix(getInt64FromFlag(cmd, "timestamp"), 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue