+13
-3
db/atproto.go
+13
-3
db/atproto.go
···
172
172
var authserverIss string
173
173
var jwkBytes string
174
174
175
-
err := db.QueryRow(`
176
-
SELECT id, atproto_did, atproto_pds_url, atproto_authserver_issuer, atproto_access_token, atproto_refresh_token, atproto_pds_nonce, atproto_authserver_nonce, atproto_dpop_private_jwk, atproto_token_expiry
175
+
err := db.QueryRow(
176
+
`
177
+
SELECT id,
178
+
atproto_did,
179
+
atproto_pds_url,
180
+
atproto_authserver_issuer,
181
+
atproto_access_token,
182
+
atproto_refresh_token,
183
+
atproto_pds_nonce,
184
+
atproto_authserver_nonce,
185
+
atproto_dpop_private_jwk,
186
+
atproto_token_expiry
177
187
FROM users
178
-
WHERE atproto_did = ? OR id`,
188
+
WHERE atproto_did = ?`,
179
189
did,
180
190
).Scan(
181
191
&oauthSession.ID,
+1
-2
oauth/oauth2.go
+1
-2
oauth/oauth2.go
···
123
123
}
124
124
125
125
userId, hasSession := session.GetUserID(r.Context())
126
-
127
126
// store token and get uid
128
-
userID, err := o.tokenReceiver.SetAccessToken(token.AccessToken, userId, hasSession)
127
+
userID, err := o.tokenReceiver.SetAccessToken(token.AccessToken, token.RefreshToken, userId, hasSession)
129
128
if err != nil {
130
129
log.Printf("OAuth2 Callback Info: TokenReceiver did not return a valid user ID for token: %s...", token.AccessToken[:min(10, len(token.AccessToken))])
131
130
}
+1
-1
oauth/service.go
+1
-1
oauth/service.go
···
16
16
type TokenReceiver interface {
17
17
// stores the access token in the db
18
18
// if there is a session, will associate the token with the session
19
-
SetAccessToken(token string, currentId int64, hasSession bool) (int64, error)
19
+
SetAccessToken(token string, refreshToken string, currentId int64, hasSession bool) (int64, error)
20
20
}
+5
-5
service/spotify/spotify.go
+5
-5
service/spotify/spotify.go
···
117
117
return nil
118
118
}
119
119
120
-
func (s *SpotifyService) SetAccessToken(token string, userId int64, hasSession bool) (int64, error) {
121
-
userID, err := s.identifyAndStoreUser(token, userId, hasSession)
120
+
func (s *SpotifyService) SetAccessToken(token string, refreshToken string, userId int64, hasSession bool) (int64, error) {
121
+
userID, err := s.identifyAndStoreUser(token, refreshToken, userId, hasSession)
122
122
if err != nil {
123
123
log.Printf("Error identifying and storing user: %v", err)
124
124
return 0, err
···
126
126
return userID, nil
127
127
}
128
128
129
-
func (s *SpotifyService) identifyAndStoreUser(token string, userId int64, hasSession bool) (int64, error) {
129
+
func (s *SpotifyService) identifyAndStoreUser(token string, refreshToken string, userId int64, hasSession bool) (int64, error) {
130
130
userProfile, err := s.fetchSpotifyProfile(token)
131
131
if err != nil {
132
132
log.Printf("Error fetching Spotify profile: %v", err)
···
151
151
return 0, fmt.Errorf("user does not seem to exist")
152
152
} else {
153
153
// overwrite prev user
154
-
user, err = s.DB.AddSpotifySession(userId, userProfile.DisplayName, userProfile.Email, userProfile.ID, token, "", tokenExpiryTime)
154
+
user, err = s.DB.AddSpotifySession(userId, userProfile.DisplayName, userProfile.Email, userProfile.ID, token, refreshToken, tokenExpiryTime)
155
155
if err != nil {
156
156
log.Printf("Error adding Spotify session for user ID %d: %v", userId, err)
157
157
return 0, err
158
158
}
159
159
}
160
160
} else {
161
-
err = s.DB.UpdateUserToken(user.ID, token, "", tokenExpiryTime)
161
+
err = s.DB.UpdateUserToken(user.ID, token, refreshToken, tokenExpiryTime)
162
162
if err != nil {
163
163
// for now log and continue
164
164
log.Printf("Error updating user token for user ID %d: %v", user.ID, err)