summaryrefslogtreecommitdiff
path: root/internal/typeutils
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2025-03-04 11:01:25 +0100
committerLibravatar GitHub <noreply@github.com>2025-03-04 10:01:25 +0000
commit829143d2636d4c0d274bf2ab4559912f472a2bc4 (patch)
treeb28175fadfbd2d02801337975560e522dd8e129b /internal/typeutils
parent[chore] fixed email template to align with the new "Log in" button + separate... (diff)
downloadgotosocial-829143d2636d4c0d274bf2ab4559912f472a2bc4.tar.xz
[feature] Add token review / delete to backend + settings panel (#3845)
Diffstat (limited to 'internal/typeutils')
-rw-r--r--internal/typeutils/internaltofrontend.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/internal/typeutils/internaltofrontend.go b/internal/typeutils/internaltofrontend.go
index 510b165d1..8bd92512a 100644
--- a/internal/typeutils/internaltofrontend.go
+++ b/internal/typeutils/internaltofrontend.go
@@ -3068,3 +3068,39 @@ func (c *Converter) WebPushSubscriptionToAPIWebPushSubscription(
Standard: true,
}, nil
}
+
+func (c *Converter) TokenToAPITokenInfo(
+ ctx context.Context,
+ token *gtsmodel.Token,
+) (*apimodel.TokenInfo, error) {
+ createdAt, err := id.TimeFromULID(token.ID)
+ if err != nil {
+ err := gtserror.Newf("error parsing time from token id: %w", err)
+ return nil, err
+ }
+
+ var lastUsed string
+ if !token.LastUsed.IsZero() {
+ lastUsed = util.FormatISO8601(token.LastUsed)
+ }
+
+ application, err := c.state.DB.GetApplicationByClientID(ctx, token.ClientID)
+ if err != nil {
+ err := gtserror.Newf("db error getting application with client id %s: %w", token.ClientID, err)
+ return nil, err
+ }
+
+ apiApplication, err := c.AppToAPIAppPublic(ctx, application)
+ if err != nil {
+ err := gtserror.Newf("error converting application to api application: %w", err)
+ return nil, err
+ }
+
+ return &apimodel.TokenInfo{
+ ID: token.ID,
+ CreatedAt: util.FormatISO8601(createdAt),
+ LastUsed: lastUsed,
+ Scope: token.Scope,
+ Application: apiApplication,
+ }, nil
+}