mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-10 22:17:44 +00:00
More proper types
This commit is contained in:
parent
69675d4d5c
commit
7c7e1e5e1c
4 changed files with 8 additions and 5 deletions
|
@ -150,7 +150,7 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset expiration timer
|
// Reset expiration timer
|
||||||
acc.TokenExpiresAt = time.Now().Add(1 * time.Hour)
|
acc.TokenExpiresAt = time.Now().Add(tokens.Expiry)
|
||||||
acc.RefreshToken = tokens.RefreshToken
|
acc.RefreshToken = tokens.RefreshToken
|
||||||
acc.AccessToken = tokens.AccessToken
|
acc.AccessToken = tokens.AccessToken
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ func (a *api) upsertAccountHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset expiration timer
|
// Reset expiration timer
|
||||||
acct.TokenExpiresAt = time.Now().Add(1 * time.Hour)
|
acct.TokenExpiresAt = time.Now().Add(tokens.Expiry)
|
||||||
acct.RefreshToken = tokens.RefreshToken
|
acct.RefreshToken = tokens.RefreshToken
|
||||||
acct.AccessToken = tokens.AccessToken
|
acct.AccessToken = tokens.AccessToken
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,9 @@ func NewError(val *fastjson.Value, status int) *Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RefreshTokenResponse struct {
|
type RefreshTokenResponse struct {
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
RefreshToken string `json:"refresh_token"`
|
RefreshToken string `json:"refresh_token"`
|
||||||
|
Expiry time.Duration `json:"expires_in"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRefreshTokenResponse(val *fastjson.Value) interface{} {
|
func NewRefreshTokenResponse(val *fastjson.Value) interface{} {
|
||||||
|
@ -39,6 +40,7 @@ func NewRefreshTokenResponse(val *fastjson.Value) interface{} {
|
||||||
|
|
||||||
rtr.AccessToken = string(val.GetStringBytes("access_token"))
|
rtr.AccessToken = string(val.GetStringBytes("access_token"))
|
||||||
rtr.RefreshToken = string(val.GetStringBytes("refresh_token"))
|
rtr.RefreshToken = string(val.GetStringBytes("refresh_token"))
|
||||||
|
rtr.Expiry = time.Duration(val.GetInt("expires_in")) * time.Second
|
||||||
|
|
||||||
return rtr
|
return rtr
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ func TestRefreshTokenResponseParsing(t *testing.T) {
|
||||||
|
|
||||||
assert.Equal(t, "***REMOVED***", rtr.AccessToken)
|
assert.Equal(t, "***REMOVED***", rtr.AccessToken)
|
||||||
assert.Equal(t, "***REMOVED***", rtr.RefreshToken)
|
assert.Equal(t, "***REMOVED***", rtr.RefreshToken)
|
||||||
|
assert.Equal(t, 1*time.Hour, rtr.Expiry)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestListingResponseParsing(t *testing.T) {
|
func TestListingResponseParsing(t *testing.T) {
|
||||||
|
|
|
@ -215,7 +215,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) {
|
||||||
// Update account
|
// Update account
|
||||||
account.AccessToken = tokens.AccessToken
|
account.AccessToken = tokens.AccessToken
|
||||||
account.RefreshToken = tokens.RefreshToken
|
account.RefreshToken = tokens.RefreshToken
|
||||||
account.TokenExpiresAt = now.Add(3600 * time.Second)
|
account.TokenExpiresAt = now.Add(tokens.Expiry)
|
||||||
|
|
||||||
// Refresh client
|
// Refresh client
|
||||||
rac = nc.reddit.NewAuthenticatedClient(account.AccountID, tokens.RefreshToken, tokens.AccessToken)
|
rac = nc.reddit.NewAuthenticatedClient(account.AccountID, tokens.RefreshToken, tokens.AccessToken)
|
||||||
|
|
Loading…
Reference in a new issue