2 files changed, 9 insertions(+), 6 deletions(-)
M db.go
M srht.go
M db.go => db.go +7 -6
@@ 15,12 15,13 @@ var installationsBucket = []byte("installations")
var ErrNotFound = fmt.Errorf("resource not found in DB")
type Installation struct {
- ID int64 `json:"-"`
- Owner string `json:"owner"`
- Org string `json:"org,omitempty"`
- CreatedAt time.Time `json:"created_at"`
- SrhtToken string `json:"srht_token,omitempty"`
- SrhtRefreshToken string `json:"srht_refresh_token,omitempty"`
+ ID int64 `json:"-"`
+ Owner string `json:"owner"`
+ Org string `json:"org,omitempty"`
+ CreatedAt time.Time `json:"created_at"`
+ SrhtToken string `json:"srht_token,omitempty"`
+ SrhtRefreshToken string `json:"srht_refresh_token,omitempty"`
+ SrhtTokenExpiresAt time.Time `json:"srht_token_expires_at,omitempty"`
}
type DB struct {
M srht.go => srht.go +2 -0
@@ 4,6 4,7 @@ import (
"context"
"fmt"
"log"
+ "time"
"git.sr.ht/~emersion/go-oauth2"
"git.sr.ht/~emersion/gqlclient"
@@ 43,6 44,7 @@ func createSrhtClient(endpoint string, oauth2Client *oauth2.Client, installation
func saveSrhtToken(ctx context.Context, db *DB, srhtEndpoint string, oauth2Client *oauth2.Client, installation *Installation, tokenResp *oauth2.TokenResp) error {
installation.SrhtToken = tokenResp.AccessToken
installation.SrhtRefreshToken = tokenResp.RefreshToken
+ installation.SrhtTokenExpiresAt = time.Now().Add(tokenResp.ExpiresIn)
srht := createSrhtClient(srhtEndpoint, oauth2Client, installation)
user, err := buildssrht.FetchUser(srht.GQL, ctx)
if err != nil {