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

fix(client): skip resource check in GetAccessToken when resource is empty string #38

Merged
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
7 changes: 4 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ func (logtoClient *LogtoClient) GetAccessToken(resource string) (AccessToken, er
return AccessToken{}, ErrNotAuthenticated
}

// TODO: do not check granted resource if resource is empty
if !slices.Contains(logtoClient.logtoConfig.Resources, resource) {
return AccessToken{}, ErrUnacknowledgedResourceFound
if resource != "" {
if !slices.Contains(logtoClient.logtoConfig.Resources, resource) {
return AccessToken{}, ErrUnacknowledgedResourceFound
}
}

accessTokenKey := buildAccessTokenKey([]string{}, resource)
Expand Down
12 changes: 3 additions & 9 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ func TestGetAccessTokenShouldReturnAccessTokenAccessTokenInTokenMap(t *testing.T
}

logtoClient := NewLogtoClient(
&LogtoConfig{
Resources: []string{""},
},
&LogtoConfig{},
&TestStorage{
data: map[string]string{
StorageKeyIdToken: "id token",
Expand All @@ -39,9 +37,7 @@ func TestGetAccessTokenShouldReturnAccessTokenAccessTokenInTokenMap(t *testing.T

func TestGetAccessTokenShouldReturnNotAuthenticatedErrIfNoIdTokenAvailable(t *testing.T) {
logtoClient := NewLogtoClient(
&LogtoConfig{
Resources: []string{""},
},
&LogtoConfig{},
&TestStorage{
data: map[string]string{
StorageKeyIdToken: "",
Expand Down Expand Up @@ -95,9 +91,7 @@ func TestGetAccessTokenShouldReturnFetchedAccessTokenAndUpdateLocalAccessTokenIf
defer patchesForVerifyIdToken.Reset()

logtoClient := NewLogtoClient(
&LogtoConfig{
Resources: []string{""},
},
&LogtoConfig{},
&TestStorage{
data: map[string]string{
StorageKeyIdToken: "id token",
Expand Down
4 changes: 1 addition & 3 deletions client/handle_sign_in_callback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ func TestHandleSignInCallbackShouldHandleCallbackCorrectly(t *testing.T) {
},
}

logtoClient := NewLogtoClient(&LogtoConfig{
Resources: []string{""},
}, storage)
logtoClient := NewLogtoClient(&LogtoConfig{}, storage)

signInCallbackRequest, createSignInCallbackRequestErr := http.NewRequest("GET", "https://example.com/sign-in-callback", nil)
assert.Nil(t, createSignInCallbackRequestErr)
Expand Down
9 changes: 2 additions & 7 deletions client/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ func TestFetchOidcConfigShouldReturnExpectedOidcConfig(t *testing.T) {
func TestLoadAccessTokenMapShouldLoadAccessTokenMapFromStorage(t *testing.T) {
expiresAt := time.Now().Unix() + 60

logtoConfig := &LogtoConfig{
Resources: []string{"testResource"},
}
logtoConfig := &LogtoConfig{}

testStorage := &TestStorage{
data: map[string]string{
Expand Down Expand Up @@ -152,10 +150,7 @@ func TestVerifyAndSaveTokenResponseShouldSaveToken(t *testing.T) {

defer patchesForVerifyIdToken.Reset()

logtoClient := NewLogtoClient(&LogtoConfig{
// TODO: do not check granted resource if resource is empty
Resources: []string{""},
}, &TestStorage{
logtoClient := NewLogtoClient(&LogtoConfig{}, &TestStorage{
data: map[string]string{},
})

Expand Down