-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtui_adapter.go
More file actions
44 lines (40 loc) · 1.12 KB
/
tui_adapter.go
File metadata and controls
44 lines (40 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package main
import (
"github.com/go-authgate/cli/tui"
"github.com/go-authgate/sdk-go/credstore"
)
// toTUITokenStorage converts credstore.Token to tui.TokenStorage.
func toTUITokenStorage(token *credstore.Token, flow, storageBackend string) *tui.TokenStorage {
if token == nil {
return nil
}
return &tui.TokenStorage{
AccessToken: token.AccessToken,
RefreshToken: token.RefreshToken,
TokenType: token.TokenType,
ExpiresAt: token.ExpiresAt,
ClientID: token.ClientID,
Flow: flow,
StorageBackend: storageBackend,
}
}
// flowFromTUI extracts the Flow field from tui.TokenStorage (nil-safe).
func flowFromTUI(ts *tui.TokenStorage) string {
if ts == nil {
return ""
}
return ts.Flow
}
// fromTUITokenStorage converts tui.TokenStorage to credstore.Token.
func fromTUITokenStorage(tuiStorage *tui.TokenStorage) *credstore.Token {
if tuiStorage == nil {
return nil
}
return &credstore.Token{
AccessToken: tuiStorage.AccessToken,
RefreshToken: tuiStorage.RefreshToken,
TokenType: tuiStorage.TokenType,
ExpiresAt: tuiStorage.ExpiresAt,
ClientID: tuiStorage.ClientID,
}
}