~emersion/hottub

d8b3ffaa7bf30eeb284f17fa2b69870697207e46 — Simon Ser 5 months ago 9778fae
Store refresh token
2 files changed, 7 insertions(+), 5 deletions(-)

M db.go
M srht.go
M db.go => db.go +6 -5
@@ 15,11 15,12 @@ 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"`
	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"`
}

type DB struct {

M srht.go => srht.go +1 -0
@@ 42,6 42,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
	srht := createSrhtClient(srhtEndpoint, oauth2Client, installation)
	user, err := buildssrht.FetchUser(srht.GQL, ctx)
	if err != nil {