Skip to content

Commit

Permalink
Fixed crash when OIDC returns nil for groups #198, added make file bu…
Browse files Browse the repository at this point in the history
…ild to include debug symbols, minor rewording
  • Loading branch information
Forceu committed Jul 29, 2024
1 parent f08490e commit 3130917
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
11 changes: 9 additions & 2 deletions internal/webserver/authentication/Authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,16 @@ func extractOauthGroups(userInfo OAuthUserClaims, groupScope string) ([]string,
return nil, fmt.Errorf("claim %s was not passed on", groupScope)
}

// Convert the interface{} to a []interface{} and then to []string
// Convert the interface{} to a []string
if groupsInterface == nil {
return []string{}, nil
}
groupsCast, ok := groupsInterface.([]any)
if !ok {
return nil, fmt.Errorf("scope %s is not an array", groupScope)
}
var groups []string
for _, group := range groupsInterface.([]interface{}) {
for _, group := range groupsCast {
groups = append(groups, group.(string))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/webserver/web/templates/html_error_auth.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<div class="card-body">
<h2 class="card-title">Unauthorised user</h2>
<br>
<p class="card-text">Login with OAuth provider was sucessful, however this user is not authorised by Gokapi.</p><br><br>
<p class="card-text">Login with OAuth provider was sucessful, however this user is not authorised to use Gokapi.</p><br><br>
<a href="./login?consent=true" class="card-link">Log in as different user</a>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
GOPACKAGE=github.com/forceu/gokapi
BUILD_FLAGS=-ldflags="-s -w -X '$(GOPACKAGE)/internal/environment.Builder=Make Script' -X '$(GOPACKAGE)/internal/environment.BuildTime=$(shell date)'"
BUILD_FLAGS_DEBUG=-ldflags="-X '$(GOPACKAGE)/internal/environment.Builder=Make Script' -X '$(GOPACKAGE)/internal/environment.BuildTime=$(shell date)'"
DOCKER_IMAGE_NAME=gokapi
CONTAINER_TOOL ?= docker

Expand All @@ -16,6 +17,14 @@ build :
go generate ./...
CGO_ENABLED=0 go build $(BUILD_FLAGS) -o ./gokapi $(GOPACKAGE)/cmd/gokapi

.PHONY: build-debug
# Build Gokapi binary
build-debug :
@echo "Building binary with debug info..."
@echo
go generate ./...
CGO_ENABLED=0 go build $(BUILD_FLAGS_DEBUG) -o ./gokapi $(GOPACKAGE)/cmd/gokapi

.PHONY: coverage
coverage:
@echo Generating coverage
Expand Down

0 comments on commit 3130917

Please sign in to comment.