Skip to content

Commit

Permalink
feat(client): persist access tokens all the time (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyijun authored Sep 9, 2022
1 parent 1d7eb84 commit 83a9697
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
10 changes: 2 additions & 8 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ type LogtoConfig struct {
Scopes []string
Resources []string
Prompt string
// TODO: Find a way to make this value default to true
PersistAccessToken bool
}

type AccessToken struct {
Expand All @@ -41,9 +39,7 @@ func NewLogtoClient(config *LogtoConfig, storage Storage) *LogtoClient {
accessTokenMap: make(map[string]AccessToken),
}

if config.PersistAccessToken {
logtoClient.loadAccessTokenMap()
}
logtoClient.loadAccessTokenMap()

return &logtoClient
}
Expand Down Expand Up @@ -77,9 +73,7 @@ func (logtoClient *LogtoClient) GetIdTokenClaims() (core.IdTokenClaims, error) {

func (logtoClient *LogtoClient) SaveAccessToken(key string, accessToken AccessToken) {
logtoClient.accessTokenMap[key] = accessToken
if logtoClient.logtoConfig.PersistAccessToken {
logtoClient.persistAccessTokenMap()
}
logtoClient.persistAccessTokenMap()
}

func (logtoClient *LogtoClient) GetAccessToken(resource string) (AccessToken, error) {
Expand Down
9 changes: 4 additions & 5 deletions gin-sample/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ var (

func main() {
logtoConfig := &client.LogtoConfig{
Endpoint: "http://localhost:3001",
AppId: "wkMqPInVTZL0Ys4K3POl7",
AppSecret: "71kbRPQ1NAVA08IBStipz",
Resources: []string{"https://api.logto.io"},
PersistAccessToken: true,
Endpoint: "http://localhost:3001",
AppId: "wkMqPInVTZL0Ys4K3POl7",
AppSecret: "71kbRPQ1NAVA08IBStipz",
Resources: []string{"https://api.logto.io"},
}

store := memstore.NewStore([]byte("secret"))
Expand Down

0 comments on commit 83a9697

Please sign in to comment.