Track access token and refresh token expiry
Also make a bunch more progress on actually updating the tokens when we need them updated.
This commit is contained in:
parent
cf01c8c5c6
commit
109495b702
11 changed files with 348 additions and 104 deletions
|
|
@ -21,7 +21,7 @@ import (
|
|||
//go:embed oauth_by_user_id.bob.sql
|
||||
var formattedQueries_oauth_by_user_id string
|
||||
|
||||
var oauthTokenByUserIdSQL = formattedQueries_oauth_by_user_id[156:550]
|
||||
var oauthTokenByUserIdSQL = formattedQueries_oauth_by_user_id[156:642]
|
||||
|
||||
type OauthTokenByUserIdQuery = orm.ModQuery[*dialect.SelectQuery, oauthTokenByUserId, OauthTokenByUserIdRow, []OauthTokenByUserIdRow, oauthTokenByUserIdTransformer]
|
||||
|
||||
|
|
@ -44,12 +44,13 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
|
|||
var t OauthTokenByUserIdRow
|
||||
row.ScheduleScanByIndex(0, &t.ID)
|
||||
row.ScheduleScanByIndex(1, &t.AccessToken)
|
||||
row.ScheduleScanByIndex(2, &t.Expires)
|
||||
row.ScheduleScanByIndex(2, &t.AccessTokenExpires)
|
||||
row.ScheduleScanByIndex(3, &t.RefreshToken)
|
||||
row.ScheduleScanByIndex(4, &t.Username)
|
||||
row.ScheduleScanByIndex(5, &t.UserID)
|
||||
row.ScheduleScanByIndex(6, &t.ArcgisID)
|
||||
row.ScheduleScanByIndex(7, &t.ArcgisLicenseTypeID)
|
||||
row.ScheduleScanByIndex(8, &t.RefreshTokenExpires)
|
||||
return &t, nil
|
||||
}, func(v any) (OauthTokenByUserIdRow, error) {
|
||||
return *(v.(*OauthTokenByUserIdRow)), nil
|
||||
|
|
@ -57,9 +58,9 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
|
|||
},
|
||||
},
|
||||
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
|
||||
q.AppendSelect(expressionTypArgs.subExpr(7, 357))
|
||||
q.SetTable(expressionTypArgs.subExpr(363, 374))
|
||||
q.AppendWhere(expressionTypArgs.subExpr(382, 394))
|
||||
q.AppendSelect(expressionTypArgs.subExpr(7, 449))
|
||||
q.SetTable(expressionTypArgs.subExpr(455, 466))
|
||||
q.AppendWhere(expressionTypArgs.subExpr(474, 486))
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
|
@ -67,12 +68,13 @@ func OauthTokenByUserId(UserID int32) *OauthTokenByUserIdQuery {
|
|||
type OauthTokenByUserIdRow = struct {
|
||||
ID int32 `db:"id"`
|
||||
AccessToken string `db:"access_token"`
|
||||
Expires time.Time `db:"expires"`
|
||||
AccessTokenExpires time.Time `db:"access_token_expires"`
|
||||
RefreshToken string `db:"refresh_token"`
|
||||
Username string `db:"username"`
|
||||
UserID int32 `db:"user_id"`
|
||||
ArcgisID null.Val[string] `db:"arcgis_id"`
|
||||
ArcgisLicenseTypeID null.Val[string] `db:"arcgis_license_type_id"`
|
||||
RefreshTokenExpires time.Time `db:"refresh_token_expires"`
|
||||
}
|
||||
|
||||
type oauthTokenByUserIdTransformer = bob.SliceTransformer[OauthTokenByUserIdRow, []OauthTokenByUserIdRow]
|
||||
|
|
@ -85,8 +87,8 @@ func (o oauthTokenByUserId) args() iter.Seq[orm.ArgWithPosition] {
|
|||
return func(yield func(arg orm.ArgWithPosition) bool) {
|
||||
if !yield(orm.ArgWithPosition{
|
||||
Name: "userID",
|
||||
Start: 392,
|
||||
Stop: 394,
|
||||
Start: 484,
|
||||
Stop: 486,
|
||||
Expression: o.UserID,
|
||||
}) {
|
||||
return
|
||||
|
|
|
|||
|
|
@ -2,5 +2,5 @@
|
|||
-- This file is meant to be re-generated in place and/or deleted at any time.
|
||||
|
||||
-- OauthTokenByUserId
|
||||
SELECT "oauth_token"."id" AS "id", "oauth_token"."access_token" AS "access_token", "oauth_token"."expires" AS "expires", "oauth_token"."refresh_token" AS "refresh_token", "oauth_token"."username" AS "username", "oauth_token"."user_id" AS "user_id", "oauth_token"."arcgis_id" AS "arcgis_id", "oauth_token"."arcgis_license_type_id" AS "arcgis_license_type_id" FROM oauth_token WHERE
|
||||
SELECT "oauth_token"."id" AS "id", "oauth_token"."access_token" AS "access_token", "oauth_token"."access_token_expires" AS "access_token_expires", "oauth_token"."refresh_token" AS "refresh_token", "oauth_token"."username" AS "username", "oauth_token"."user_id" AS "user_id", "oauth_token"."arcgis_id" AS "arcgis_id", "oauth_token"."arcgis_license_type_id" AS "arcgis_license_type_id", "oauth_token"."refresh_token_expires" AS "refresh_token_expires" FROM oauth_token WHERE
|
||||
user_id = $1;
|
||||
|
|
|
|||
|
|
@ -84,8 +84,8 @@ func TestOauthTokenByUserId(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(columns) != 8 {
|
||||
t.Fatalf("expected %d columns, got %d", 8, len(columns))
|
||||
if len(columns) != 9 {
|
||||
t.Fatalf("expected %d columns, got %d", 9, len(columns))
|
||||
}
|
||||
|
||||
if columns[0] != "id" {
|
||||
|
|
@ -96,8 +96,8 @@ func TestOauthTokenByUserId(t *testing.T) {
|
|||
t.Fatalf("expected column %d to be %s, got %s", 1, "access_token", columns[1])
|
||||
}
|
||||
|
||||
if columns[2] != "expires" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 2, "expires", columns[2])
|
||||
if columns[2] != "access_token_expires" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 2, "access_token_expires", columns[2])
|
||||
}
|
||||
|
||||
if columns[3] != "refresh_token" {
|
||||
|
|
@ -119,5 +119,9 @@ func TestOauthTokenByUserId(t *testing.T) {
|
|||
if columns[7] != "arcgis_license_type_id" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 7, "arcgis_license_type_id", columns[7])
|
||||
}
|
||||
|
||||
if columns[8] != "refresh_token_expires" {
|
||||
t.Fatalf("expected column %d to be %s, got %s", 8, "refresh_token_expires", columns[8])
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue