Skip to content

Commit 3130917

Browse files
committed
Fixed crash when OIDC returns nil for groups #198, added make file build to include debug symbols, minor rewording
1 parent f08490e commit 3130917

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

internal/webserver/authentication/Authentication.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,16 @@ func extractOauthGroups(userInfo OAuthUserClaims, groupScope string) ([]string,
169169
return nil, fmt.Errorf("claim %s was not passed on", groupScope)
170170
}
171171

172-
// Convert the interface{} to a []interface{} and then to []string
172+
// Convert the interface{} to a []string
173+
if groupsInterface == nil {
174+
return []string{}, nil
175+
}
176+
groupsCast, ok := groupsInterface.([]any)
177+
if !ok {
178+
return nil, fmt.Errorf("scope %s is not an array", groupScope)
179+
}
173180
var groups []string
174-
for _, group := range groupsInterface.([]interface{}) {
181+
for _, group := range groupsCast {
175182
groups = append(groups, group.(string))
176183
}
177184

internal/webserver/web/templates/html_error_auth.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<div class="card-body">
88
<h2 class="card-title">Unauthorised user</h2>
99
<br>
10-
<p class="card-text">Login with OAuth provider was sucessful, however this user is not authorised by Gokapi.</p><br><br>
10+
<p class="card-text">Login with OAuth provider was sucessful, however this user is not authorised to use Gokapi.</p><br><br>
1111
<a href="./login?consent=true" class="card-link">Log in as different user</a>
1212
</div>
1313
</div>

makefile

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
GOPACKAGE=github.com/forceu/gokapi
22
BUILD_FLAGS=-ldflags="-s -w -X '$(GOPACKAGE)/internal/environment.Builder=Make Script' -X '$(GOPACKAGE)/internal/environment.BuildTime=$(shell date)'"
3+
BUILD_FLAGS_DEBUG=-ldflags="-X '$(GOPACKAGE)/internal/environment.Builder=Make Script' -X '$(GOPACKAGE)/internal/environment.BuildTime=$(shell date)'"
34
DOCKER_IMAGE_NAME=gokapi
45
CONTAINER_TOOL ?= docker
56

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

20+
.PHONY: build-debug
21+
# Build Gokapi binary
22+
build-debug :
23+
@echo "Building binary with debug info..."
24+
@echo
25+
go generate ./...
26+
CGO_ENABLED=0 go build $(BUILD_FLAGS_DEBUG) -o ./gokapi $(GOPACKAGE)/cmd/gokapi
27+
1928
.PHONY: coverage
2029
coverage:
2130
@echo Generating coverage

0 commit comments

Comments
 (0)