Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client): extract storage keys #27

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,19 @@ func (logtoClient *LogtoClient) IsAuthenticated() bool {
}

func (logtoClient *LogtoClient) GetRefreshToken() string {
return logtoClient.storage.GetItem("logto_refresh_token")
return logtoClient.storage.GetItem(StorageKeyRefreshToken)
}

func (logtoClient *LogtoClient) SetRefreshToken(refreshToken string) {
logtoClient.storage.SetItem("logto_refresh_token", refreshToken)
logtoClient.storage.SetItem(StorageKeyRefreshToken, refreshToken)
}

func (LogtoClient *LogtoClient) GetIdToken() string {
return LogtoClient.storage.GetItem("logto_id_token")
return LogtoClient.storage.GetItem(StorageKeyIdToken)
}

func (logtoClient *LogtoClient) SetIdToken(idToken string) {
logtoClient.storage.SetItem("logto_id_token", idToken)
logtoClient.storage.SetItem(StorageKeyIdToken, idToken)
}

func (logtoClient *LogtoClient) GetIdTokenClaims() (core.IdTokenClaims, error) {
Expand Down
8 changes: 8 additions & 0 deletions client/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package client

const (
StorageKeySignInContext = "logto_sign_in_context"
StorageKeyRefreshToken = "logto_refresh_token"
StorageKeyIdToken = "logto_id_token"
StorageKeyAccessTokenMap = "logto_access_token_map"
)
2 changes: 1 addition & 1 deletion client/handle_sign_in_callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (logtoClient *LogtoClient) HandleSignInCallback(request *http.Request) erro
return fetchTokenErr
}

logtoClient.storage.SetItem("logto_sign_in_context", "")
logtoClient.storage.SetItem(StorageKeySignInContext, "")

accessToken := AccessToken{
Token: codeTokenResponse.AccessToken,
Expand Down
2 changes: 1 addition & 1 deletion client/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (logtoClient *LogtoClient) persistAccessTokenMap() {
if err != nil {
return
}
logtoClient.storage.SetItem("logto_access_token_map", string(accessTokenMapJsonString))
logtoClient.storage.SetItem(StorageKeyAccessTokenMap, string(accessTokenMapJsonString))
}

func (logtoClient *LogtoClient) createRemoteJwks(jwksUri string) (*jose.JSONWebKeySet, error) {
Expand Down
2 changes: 1 addition & 1 deletion client/sign_in.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (logtoClient *LogtoClient) SignIn(redirectUri string) (string, error) {
return "", marshalErr
}

logtoClient.storage.SetItem("logto_sign_in_context", string(signInContextJsonValue))
logtoClient.storage.SetItem(StorageKeySignInContext, string(signInContextJsonValue))

return signInUri, nil
}
6 changes: 3 additions & 3 deletions client/sign_out.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func (logtoClient *LogtoClient) SignOut(postLogoutRedirectUri string) (string, e
refreshToken := logtoClient.GetRefreshToken()

logtoClient.accessTokenMap = make(map[string]AccessToken)
logtoClient.storage.SetItem("logto_access_token_map", "")
logtoClient.storage.SetItem("logto_refresh_token", "")
logtoClient.storage.SetItem("logto_id_token", "")
logtoClient.storage.SetItem(StorageKeyAccessTokenMap, "")
logtoClient.storage.SetItem(StorageKeyRefreshToken, "")
logtoClient.storage.SetItem(StorageKeyIdToken, "")

oidcConfig, fetchOidcConfigErr := logtoClient.fetchOidcConfig()

Expand Down