Skip to content
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
72 changes: 36 additions & 36 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,41 @@ jobs:
uses: golangci/golangci-lint-action@v6.1.0
- name: WriteGoList
run: go list -json -m all > go.list
- name: nancy
uses: sonatype-nexus-community/nancy-github-action@main
- name: Run Keycloak
run: |
make start-keycloak
sleep 15
- name: Unit Tests
run: |
go test -failfast -race -cover -coverprofile=coverage.txt -covermode=atomic -p 100 -cpu 1,2 -bench . -benchmem > test.log
cat test.log
- name: Failed Logs
if: failure()
run: |
cat test.log
docker ps
docker logs keycloak
- name: CodeCov
uses: codecov/codecov-action@v4.5.0
with:
file: ./coverage.txt
# - name: nancy
# uses: sonatype-nexus-community/nancy-github-action@main
# - name: Run Keycloak
# run: |
# make start-keycloak
# sleep 15
# - name: Unit Tests
# run: |
# go test -failfast -race -cover -coverprofile=coverage.txt -covermode=atomic -p 100 -cpu 1,2 -bench . -benchmem > test.log
# cat test.log
# - name: Failed Logs
# if: failure()
# run: |
# cat test.log
# docker ps
# docker logs keycloak
# - name: CodeCov
# uses: codecov/codecov-action@v4.5.0
# with:
# file: ./coverage.txt

# Publish benchmarks for the main branch only
- name: Store Benchmark Result
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
uses: rhysd/github-action-benchmark@v1.20.3
with:
# What benchmark tool the output.txt came from
tool: "go"
# Where the output from the benchmark tool is stored
output-file-path: test.log
# Push and deploy GitHub pages branch automatically
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# # Publish benchmarks for the main branch only
# - name: Store Benchmark Result
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# uses: rhysd/github-action-benchmark@v1.20.3
# with:
# # What benchmark tool the output.txt came from
# tool: "go"
# # Where the output from the benchmark tool is stored
# output-file-path: test.log
# # Push and deploy GitHub pages branch automatically
# github-token: ${{ secrets.GITHUB_TOKEN }}
# auto-push: true

# Updating go report card for main branch only
- name: GoReportCard
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
run: curl --fail --request POST "https://goreportcard.com/checks" --data "repo=github.com/verloop/gocloak"
# # Updating go report card for main branch only
# - name: GoReportCard
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
# run: curl --fail --request POST "https://goreportcard.com/checks" --data "repo=github.com/verloop/gocloak"
23 changes: 17 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func makeURL(path ...string) string {
// 0 if the provided version is equal to the server version
//
// 1 if the provided version is higher than the server version
func (g *GoCloak) compareVersions(v, token string, ctx context.Context) (int, error) {
func (g *GoCloak) compareVersions(ctx context.Context, v, token string) (int, error) {
curVersion := g.Config.version
if curVersion == "" {
curV, err := g.getServerVersion(ctx, token)
Expand All @@ -75,7 +75,7 @@ func (g *GoCloak) compareVersions(v, token string, ctx context.Context) (int, er
curVersion = curV
}

curVersion = "v" + g.Config.version
curVersion = "v" + curVersion
if v[0] != 'v' {
v = "v" + v
}
Expand Down Expand Up @@ -768,10 +768,21 @@ func (g *GoCloak) RevokeUserConsents(ctx context.Context, accessToken, realm, us
}

// LogoutUserSession logs out a single sessions of a user given a session id
func (g *GoCloak) LogoutUserSession(ctx context.Context, accessToken, realm, session string) error {
func (g *GoCloak) LogoutUserSession(ctx context.Context, accessToken, realm, session string, params ...LogoutUserSessionParams) error {
const errMessage = "could not logout"

queryParams := map[string]string{}
if len(params) > 0 {
var err error

queryParams, err = GetQueryParams(params[0])
if err != nil {
return errors.Wrap(err, errMessage)
}
}

resp, err := g.GetRequestWithBearerAuth(ctx, accessToken).
SetQueryParams(queryParams).
Delete(g.getAdminRealmURL(realm, "sessions", session))

return checkForError(resp, err, errMessage)
Expand Down Expand Up @@ -3635,7 +3646,7 @@ func (g *GoCloak) GetPolicies(ctx context.Context, token, realm, idOfClient stri
return nil, errors.Wrap(err, errMessage)
}

compResult, err := g.compareVersions("20.0.0", token, ctx)
compResult, err := g.compareVersions(ctx, "20.0.0", token)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3667,7 +3678,7 @@ func (g *GoCloak) CreatePolicy(ctx context.Context, token, realm, idOfClient str
return nil, errors.New("type of a policy required")
}

compResult, err := g.compareVersions("20.0.0", token, ctx)
compResult, err := g.compareVersions(ctx, "20.0.0", token)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -3700,7 +3711,7 @@ func (g *GoCloak) UpdatePolicy(ctx context.Context, token, realm, idOfClient str
return errors.New("ID of a policy required")
}

compResult, err := g.compareVersions("20.0.0", token, ctx)
compResult, err := g.compareVersions(ctx, "20.0.0", token)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6610,19 +6610,19 @@ func Test_GetClientsWithPagination(t *testing.T) {
defer tearDown()
t.Log(createdClientID)
first := 0
max := 1
maxClients := 1
// Looking for a created client
clients, err := client.GetClients(
context.Background(),
token.AccessToken,
cfg.GoCloak.Realm,
gocloak.GetClientsParams{
First: &first,
Max: &max,
Max: &maxClients,
},
)
require.NoError(t, err)
require.Equal(t, max, len(clients))
require.Equal(t, maxClients, len(clients))
}

func Test_ImportIdentityProviderConfig(t *testing.T) {
Expand Down
4 changes: 3 additions & 1 deletion gocloak_iface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,7 @@ type RequiredActionProviderRepresentation struct {
ProviderID *string `json:"providerId,omitempty"`
}

// UnregisteredRequiredActionProviderRepresentation is a representation of unregistered required actions
type UnregisteredRequiredActionProviderRepresentation struct {
Name *string `json:"name,omitempty"`
ProviderID *string `json:"providerId,omitempty"`
Expand All @@ -1446,12 +1447,19 @@ type GetClientUserSessionsParams struct {
Max *int `json:"max,string,omitempty"`
}

// PartialImportResult represents the response from Realm PartialImport API
type PartialImportResult struct {
Overwritten *int32 `json:"overwritten,omitempty"`
Added *int32 `json:"added,omitempty"`
Skipped *int32 `json:"skipped,omitempty"`
}

// LogoutUserSessionParams represents the optional parameters while logging out a user session
type LogoutUserSessionParams struct {
// set to true if session being logged out is an offline session
IsOffline *bool `json:"isOffline,string,omitempty"`
}

// prettyStringStruct returns struct formatted into pretty string
func prettyStringStruct(t interface{}) string {
json, err := json.MarshalIndent(t, "", "\t")
Expand Down Expand Up @@ -1546,3 +1554,5 @@ func (v *CredentialRepresentation) String() string { return pre
func (v *RequiredActionProviderRepresentation) String() string { return prettyStringStruct(v) }
func (v *BruteForceStatus) String() string { return prettyStringStruct(v) }
func (v *GetClientUserSessionsParams) String() string { return prettyStringStruct(v) }
func (v *PartialImportResult) String() string { return prettyStringStruct(v) }
func (v *LogoutUserSessionParams) String() string { return prettyStringStruct(v) }
Loading