More proper types

This commit is contained in:
Andre Medeiros 2022-03-28 17:33:01 -04:00
parent 69675d4d5c
commit 7c7e1e5e1c
4 changed files with 8 additions and 5 deletions

View file

@ -150,7 +150,7 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
}
// Reset expiration timer
acc.TokenExpiresAt = time.Now().Add(1 * time.Hour)
acc.TokenExpiresAt = time.Now().Add(tokens.Expiry)
acc.RefreshToken = tokens.RefreshToken
acc.AccessToken = tokens.AccessToken
@ -215,7 +215,7 @@ func (a *api) upsertAccountHandler(w http.ResponseWriter, r *http.Request) {
}
// Reset expiration timer
acct.TokenExpiresAt = time.Now().Add(1 * time.Hour)
acct.TokenExpiresAt = time.Now().Add(tokens.Expiry)
acct.RefreshToken = tokens.RefreshToken
acct.AccessToken = tokens.AccessToken

View file

@ -32,6 +32,7 @@ func NewError(val *fastjson.Value, status int) *Error {
type RefreshTokenResponse struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
Expiry time.Duration `json:"expires_in"`
}
func NewRefreshTokenResponse(val *fastjson.Value) interface{} {
@ -39,6 +40,7 @@ func NewRefreshTokenResponse(val *fastjson.Value) interface{} {
rtr.AccessToken = string(val.GetStringBytes("access_token"))
rtr.RefreshToken = string(val.GetStringBytes("refresh_token"))
rtr.Expiry = time.Duration(val.GetInt("expires_in")) * time.Second
return rtr
}

View file

@ -41,6 +41,7 @@ func TestRefreshTokenResponseParsing(t *testing.T) {
assert.Equal(t, "***REMOVED***", rtr.AccessToken)
assert.Equal(t, "***REMOVED***", rtr.RefreshToken)
assert.Equal(t, 1*time.Hour, rtr.Expiry)
}
func TestListingResponseParsing(t *testing.T) {

View file

@ -215,7 +215,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
// Update account
account.AccessToken = tokens.AccessToken
account.RefreshToken = tokens.RefreshToken
account.TokenExpiresAt = now.Add(3600 * time.Second)
account.TokenExpiresAt = now.Add(tokens.Expiry)
// Refresh client
rac = nc.reddit.NewAuthenticatedClient(account.AccountID, tokens.RefreshToken, tokens.AccessToken)