summaryrefslogtreecommitdiff
path: root/internal/gtsmodel/token.go
diff options
context:
space:
mode:
authorLibravatar tsmethurst <tobi.smethurst@protonmail.com>2021-09-01 11:45:01 +0200
committerLibravatar tsmethurst <tobi.smethurst@protonmail.com>2021-09-01 11:45:01 +0200
commit684bd56528c5ffa37af8340b8b141fe390dd05a4 (patch)
tree4a78d70c2ca7f15e47f8a2e6bc51d62c99b0f52d /internal/gtsmodel/token.go
parentMerge branch 'struct_validation' of github.com:superseriousbusiness/gotosocia... (diff)
downloadgotosocial-684bd56528c5ffa37af8340b8b141fe390dd05a4.tar.xz
move oauth models into gtsmodel
Diffstat (limited to 'internal/gtsmodel/token.go')
-rw-r--r--internal/gtsmodel/token.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/internal/gtsmodel/token.go b/internal/gtsmodel/token.go
new file mode 100644
index 000000000..1ede26aee
--- /dev/null
+++ b/internal/gtsmodel/token.go
@@ -0,0 +1,50 @@
+/*
+ GoToSocial
+ Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package gtsmodel
+
+import "time"
+
+// Token is a translation of the gotosocial token with the ExpiresIn fields replaced with ExpiresAt.
+//
+// Explanation for this: gotosocial assumes an in-memory or file database of some kind, where a time-to-live parameter (TTL) can be defined,
+// and tokens with expired TTLs are automatically removed. Since some databases don't have that feature, it's easier to set an expiry time and
+// then periodically sweep out tokens when that time has passed.
+//
+// Note that this struct does *not* satisfy the token interface shown here: https://github.com/superseriousbusiness/oauth2/blob/master/model.go#L22
+// and implemented here: https://github.com/superseriousbusiness/oauth2/blob/master/models/token.go.
+// As such, manual translation is always required between Token and the gotosocial *model.Token. The helper functions oauthTokenToPGToken
+// and pgTokenToOauthToken can be used for that.
+type Token struct {
+ ID string `validate:"ulid" bun:"type:CHAR(26),pk,nullzero,notnull"`
+ ClientID string
+ UserID string
+ RedirectURI string
+ Scope string
+ Code string `bun:"default:'',pk"`
+ CodeChallenge string
+ CodeChallengeMethod string
+ CodeCreateAt time.Time `bun:",nullzero"`
+ CodeExpiresAt time.Time `bun:",nullzero"`
+ Access string `bun:"default:'',pk"`
+ AccessCreateAt time.Time `bun:",nullzero"`
+ AccessExpiresAt time.Time `bun:",nullzero"`
+ Refresh string `bun:"default:'',pk"`
+ RefreshCreateAt time.Time `bun:",nullzero"`
+ RefreshExpiresAt time.Time `bun:",nullzero"`
+}