Skip to content

Commit c195186

Browse files
Add embedded SQLite support, refactor DB client, and clean up codebase
Add support for embedded sqlite and fix integration tests Clean make file and structure Update README Address review comments Update sqlite schema Address review comments Refactor services and db client
1 parent a0de934 commit c195186

23 files changed

Lines changed: 615 additions & 248 deletions

File tree

Makefile

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,56 @@
1-
# Variables
1+
# Constants.
2+
VERSION_FILE=version.txt
23
BINARY_NAME=thunder
3-
OUTPUT_DIR=target
4-
ZIP_FILE=product-is-thunder.zip
54
REPOSITORY_DIR=cmd/server/repository
6-
VERSION_FILE=version.txt
5+
OUTPUT_DIR=target
6+
BUILD_DIR=$(OUTPUT_DIR)/.build
7+
8+
# Variable constants.
9+
VERSION=$(shell cat $(VERSION_FILE))
10+
# ZIP_FILE_NAME=${BINARY_NAME_PREFIX}-$(VERSION)
11+
PRODUCT_FOLDER=$(BINARY_NAME)-$(VERSION)
12+
13+
# Default target.
14+
all: clean build test
715

8-
# Default target
9-
all: clean build package
10-
11-
# Build the Go project
12-
build:
13-
go build -o $(OUTPUT_DIR)/$(BINARY_NAME) ./cmd/server
14-
15-
# Package the binary and repository directory into a zip file
16-
package: build
17-
VERSION=$(shell cat $(VERSION_FILE)) && \
18-
mkdir -p $(OUTPUT_DIR)/thunder-$$VERSION && \
19-
cp $(OUTPUT_DIR)/$(BINARY_NAME) $(OUTPUT_DIR)/thunder-$$VERSION/ && \
20-
cp -r $(REPOSITORY_DIR) $(OUTPUT_DIR)/thunder-$$VERSION/ && \
21-
cp $(VERSION_FILE) $(OUTPUT_DIR)/thunder-$$VERSION/ && \
22-
cp -r scripts $(OUTPUT_DIR)/thunder-$$VERSION/ && \
23-
cp -r dbscripts $(OUTPUT_DIR)/thunder-$$VERSION/ && \
24-
cd $(OUTPUT_DIR) && zip -r thunder-$$VERSION.zip thunder-$$VERSION && \
25-
rm -rf thunder-$$VERSION && \
26-
rm $(BINARY_NAME)
27-
28-
# Clean up build artifacts
16+
# Clean up build artifacts.
2917
clean:
3018
rm -rf $(OUTPUT_DIR)
3119

32-
.PHONY: all build package clean
20+
# Build project and package it.
21+
build: _build _package
22+
23+
# Build the Go project.
24+
_build:
25+
mkdir -p $(BUILD_DIR) && \
26+
go build -o $(BUILD_DIR)/$(BINARY_NAME) ./cmd/server
27+
28+
# Package the binary and repository directory into a zip file.
29+
_package:
30+
mkdir -p $(OUTPUT_DIR)/$(PRODUCT_FOLDER) && \
31+
cp $(BUILD_DIR)/$(BINARY_NAME) $(OUTPUT_DIR)/$(PRODUCT_FOLDER)/ && \
32+
cp -r $(REPOSITORY_DIR) $(OUTPUT_DIR)/$(PRODUCT_FOLDER)/ && \
33+
cp $(VERSION_FILE) $(OUTPUT_DIR)/$(PRODUCT_FOLDER)/ && \
34+
cp -r scripts $(OUTPUT_DIR)/$(PRODUCT_FOLDER)/ && \
35+
cp -r dbscripts $(OUTPUT_DIR)/$(PRODUCT_FOLDER)/ && \
36+
cd $(OUTPUT_DIR) && zip -r $(PRODUCT_FOLDER).zip $(PRODUCT_FOLDER) && \
37+
rm -rf $(PRODUCT_FOLDER) && \
38+
rm -rf $(BUILD_DIR)
39+
40+
# Run all tests.
41+
test: _integration-test
42+
43+
# Run integration tests.
44+
_integration-test:
45+
@echo "Running integration tests..."
46+
@go run ./tests/integration/run_tests.go
47+
48+
help:
49+
@echo "Makefile targets:"
50+
@echo " all - Clean, build, and test the project."
51+
@echo " clean - Remove build artifacts."
52+
@echo " build - Build the Go project."
53+
@echo " test - Run all tests."
54+
@echo " help - Show the help message."
55+
56+
.PHONY: all clean build _build _package test _integration-test help

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ docker run -d -p 5432:5432 --name postgres \
4444
### 🗂 Step 2: Initialize the Database
4545

4646
```bash
47-
docker exec -i postgres psql -U asgthunder -d thunderdb < dbscripts/schema.sql
47+
docker exec -i postgres psql -U asgthunder -d thunderdb < dbscripts/postgress.sql
4848
```
4949

5050
---
@@ -83,14 +83,16 @@ curl -k -X POST https://localhost:8090/oauth2/token \
8383

8484
## 🧪 Running Integration Tests
8585

86+
Building the product with `make all` will run the integration tests by default. However if you want to run the tests manually, follow the steps below.
87+
8688
### 1️⃣ Build the Project
8789

8890
```bash
89-
make all
91+
make clean build
9092
```
9193

9294
### 2️⃣ Run the Tests
9395

9496
```bash
95-
go run ./tests/integration/run_tests.go
97+
make test
9698
```

cmd/server/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func main() {
5353
}
5454

5555
// Initialize the multiplexer and register services.
56-
mux := initMultiPlexer(logger, cfg)
56+
mux := initMultiPlexer(logger)
5757
if mux == nil {
5858
logger.Fatal("Failed to initialize multiplexer")
5959
}
@@ -99,14 +99,19 @@ func initThunderConfigurations(logger *zap.Logger, thunderHome string) *config.C
9999
logger.Fatal("Failed to load private key", zap.Error(err))
100100
}
101101

102+
// Initialize runtime configurations.
103+
if err := config.InitializeThunderRuntime(thunderHome, cfg); err != nil {
104+
logger.Fatal("Failed to initialize thunder runtime", zap.Error(err))
105+
}
106+
102107
return cfg
103108
}
104109

105110
// initMultiPlexer initializes the HTTP multiplexer and registers the services.
106-
func initMultiPlexer(logger *zap.Logger, cfg *config.Config) *http.ServeMux {
111+
func initMultiPlexer(logger *zap.Logger) *http.ServeMux {
107112

108113
mux := http.NewServeMux()
109-
serviceManager := managers.NewServiceManager(mux, cfg)
114+
serviceManager := managers.NewServiceManager(mux)
110115

111116
// Register the services.
112117
err := serviceManager.RegisterServices()

dbscripts/sqlite.sql

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- Table to store basic service provider (app) details.
2+
CREATE TABLE SP_APP (
3+
ID INTEGER PRIMARY KEY AUTOINCREMENT,
4+
APP_NAME VARCHAR(255) NOT NULL,
5+
APP_ID VARCHAR(36) UNIQUE NOT NULL,
6+
VERSION VARCHAR(50) NOT NULL
7+
);
8+
9+
-- Table to store OAuth configurations for SP apps.
10+
CREATE TABLE IDN_OAUTH_CONSUMER_APPS (
11+
ID INTEGER PRIMARY KEY AUTOINCREMENT,
12+
CONSUMER_KEY VARCHAR(255) NOT NULL,
13+
CONSUMER_SECRET VARCHAR(255) NOT NULL,
14+
APP_ID VARCHAR(36) NOT NULL,
15+
CALLBACK_URIS TEXT,
16+
GRANT_TYPES TEXT
17+
);
18+
19+
-- Table to store inbound auth configs (e.g., OAuth, SAML) for SP apps.
20+
CREATE TABLE SP_INBOUND_AUTH (
21+
ID INTEGER PRIMARY KEY AUTOINCREMENT,
22+
INBOUND_AUTH_KEY VARCHAR(255) NOT NULL,
23+
INBOUND_AUTH_TYPE VARCHAR(50) NOT NULL,
24+
APP_ID VARCHAR(36) NOT NULL
25+
);
26+
27+
-- Insert sample data into the tables.
28+
INSERT INTO SP_APP (APP_NAME, APP_ID, VERSION) VALUES ('Test SPA', '550e8400-e29b-41d4-a716-446655440000', '1.0');
29+
30+
INSERT INTO IDN_OAUTH_CONSUMER_APPS (CONSUMER_KEY, CONSUMER_SECRET, APP_ID, CALLBACK_URIS, GRANT_TYPES)
31+
VALUES ('client123', 'secret123', '550e8400-e29b-41d4-a716-446655440000', 'http://example.com/callback', 'client_credentials');
32+
33+
INSERT INTO SP_INBOUND_AUTH (INBOUND_AUTH_KEY, INBOUND_AUTH_TYPE, APP_ID)
34+
VALUES ('client123', 'oauth2', '550e8400-e29b-41d4-a716-446655440000');

go.mod

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,21 @@ require (
77
github.com/stretchr/testify v1.10.0
88
go.uber.org/zap v1.27.0
99
gopkg.in/yaml.v3 v3.0.1
10+
modernc.org/sqlite v1.37.0
1011
)
1112

1213
require (
1314
github.com/davecgh/go-spew v1.1.1 // indirect
15+
github.com/dustin/go-humanize v1.0.1 // indirect
16+
github.com/google/uuid v1.6.0 // indirect
17+
github.com/mattn/go-isatty v0.0.20 // indirect
18+
github.com/ncruces/go-strftime v0.1.9 // indirect
1419
github.com/pmezard/go-difflib v1.0.0 // indirect
20+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
1521
go.uber.org/multierr v1.11.0 // indirect
22+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 // indirect
23+
golang.org/x/sys v0.31.0 // indirect
24+
modernc.org/libc v1.62.1 // indirect
25+
modernc.org/mathutil v1.7.1 // indirect
26+
modernc.org/memory v1.9.1 // indirect
1627
)

go.sum

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
22
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3+
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
4+
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
5+
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
6+
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
7+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
8+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
39
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
410
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
11+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
12+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
13+
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
14+
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
515
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
616
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
17+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
18+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
719
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
820
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
921
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
@@ -12,7 +24,42 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
1224
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
1325
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
1426
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
27+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
28+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
29+
golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU=
30+
golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
31+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
32+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
33+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
34+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
35+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
36+
golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU=
37+
golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ=
1538
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
1639
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
1740
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
1841
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
42+
modernc.org/cc/v4 v4.25.2 h1:T2oH7sZdGvTaie0BRNFbIYsabzCxUQg8nLqCdQ2i0ic=
43+
modernc.org/cc/v4 v4.25.2/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0=
44+
modernc.org/ccgo/v4 v4.25.1 h1:TFSzPrAGmDsdnhT9X2UrcPMI3N/mJ9/X9ykKXwLhDsU=
45+
modernc.org/ccgo/v4 v4.25.1/go.mod h1:njjuAYiPflywOOrm3B7kCB444ONP5pAVr8PIEoE0uDw=
46+
modernc.org/fileutil v1.3.0 h1:gQ5SIzK3H9kdfai/5x41oQiKValumqNTDXMvKo62HvE=
47+
modernc.org/fileutil v1.3.0/go.mod h1:XatxS8fZi3pS8/hKG2GH/ArUogfxjpEKs3Ku3aK4JyQ=
48+
modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI=
49+
modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito=
50+
modernc.org/libc v1.62.1 h1:s0+fv5E3FymN8eJVmnk0llBe6rOxCu/DEU+XygRbS8s=
51+
modernc.org/libc v1.62.1/go.mod h1:iXhATfJQLjG3NWy56a6WVU73lWOcdYVxsvwCgoPljuo=
52+
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
53+
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
54+
modernc.org/memory v1.9.1 h1:V/Z1solwAVmMW1yttq3nDdZPJqV1rM05Ccq6KMSZ34g=
55+
modernc.org/memory v1.9.1/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
56+
modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8=
57+
modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns=
58+
modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w=
59+
modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE=
60+
modernc.org/sqlite v1.37.0 h1:s1TMe7T3Q3ovQiK2Ouz4Jwh7dw4ZDqbebSDTlSJdfjI=
61+
modernc.org/sqlite v1.37.0/go.mod h1:5YiWv+YviqGMuGw4V+PNplcyaJ5v+vQd7TQOgkACoJM=
62+
modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0=
63+
modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A=
64+
modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y=
65+
modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM=

internal/application/provider/applicationprovider.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package provider
2020

2121
import (
2222
"github.com/asgardeo/thunder/internal/application/service"
23-
"github.com/asgardeo/thunder/internal/system/config"
2423
)
2524

2625
// ApplicationProviderInterface defines the interface for the application provider.
@@ -29,20 +28,16 @@ type ApplicationProviderInterface interface {
2928
}
3029

3130
// ApplicationProvider is the default implementation of the ApplicationProviderInterface.
32-
type ApplicationProvider struct {
33-
config *config.Config
34-
}
31+
type ApplicationProvider struct{}
3532

3633
// NewApplicationProvider creates a new instance of ApplicationProvider.
37-
func NewApplicationProvider(cfg *config.Config) ApplicationProviderInterface {
34+
func NewApplicationProvider() ApplicationProviderInterface {
3835

39-
return &ApplicationProvider{
40-
config: cfg,
41-
}
36+
return &ApplicationProvider{}
4237
}
4338

4439
// GetApplicationService returns the application service instance.
4540
func (ap *ApplicationProvider) GetApplicationService() service.ApplicationServiceInterface {
4641

47-
return service.GetApplicationService(ap.config)
42+
return service.GetApplicationService()
4843
}

internal/application/service/applicationservice.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"errors"
2323

2424
"github.com/asgardeo/thunder/internal/application/model"
25-
"github.com/asgardeo/thunder/internal/system/config"
26-
"github.com/asgardeo/thunder/internal/system/database"
25+
dbprovider "github.com/asgardeo/thunder/internal/system/database/provider"
2726
"github.com/asgardeo/thunder/internal/system/log"
27+
"github.com/asgardeo/thunder/internal/utils"
2828

2929
"go.uber.org/zap"
3030
)
@@ -35,16 +35,12 @@ type ApplicationServiceInterface interface {
3535
}
3636

3737
// ApplicationService is the default implementation of the ApplicationServiceInterface.
38-
type ApplicationService struct {
39-
config *config.Config
40-
}
38+
type ApplicationService struct{}
4139

4240
// GetApplicationService creates a new instance of ApplicationService.
43-
func GetApplicationService(config *config.Config) ApplicationServiceInterface {
41+
func GetApplicationService() ApplicationServiceInterface {
4442

45-
return &ApplicationService{
46-
config: config,
47-
}
43+
return &ApplicationService{}
4844
}
4945

5046
// GetOAuthApplication retrieves the OAuth application based on the client Id.
@@ -57,9 +53,9 @@ func (as *ApplicationService) GetOAuthApplication(clientId string) (*model.OAuth
5753
return nil, errors.New("client ID cannot be empty")
5854
}
5955

60-
dbClient, err := database.GetDriver("identity", as.config)
56+
dbClient, err := dbprovider.NewDBProvider().GetDBClient("identity")
6157
if err != nil {
62-
logger.Error("Failed to get database driver", zap.Error(err))
58+
logger.Error("Failed to get database client", zap.Error(err))
6359
return nil, err
6460
}
6561
defer dbClient.Close()
@@ -95,7 +91,7 @@ func (as *ApplicationService) GetOAuthApplication(clientId string) (*model.OAuth
9591
redirectURIs := []string{}
9692
if row["callback_uris"] != nil {
9793
if uris, ok := row["callback_uris"].(string); ok {
98-
redirectURIs = database.ParseStringArray(uris)
94+
redirectURIs = utils.ParseStringArray(uris)
9995
} else {
10096
return nil, errors.New("failed to parse callback_uris as string")
10197
}
@@ -104,7 +100,7 @@ func (as *ApplicationService) GetOAuthApplication(clientId string) (*model.OAuth
104100
allowedGrantTypes := []string{}
105101
if row["grant_types"] != nil {
106102
if grants, ok := row["grant_types"].(string); ok {
107-
allowedGrantTypes = database.ParseStringArray(grants)
103+
allowedGrantTypes = utils.ParseStringArray(grants)
108104
} else {
109105
return nil, errors.New("failed to parse grant_types as string")
110106
}

internal/identity/oauth2/token/tokenhandler.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,13 @@ import (
2727
"github.com/asgardeo/thunder/internal/identity/oauth2/constants"
2828
"github.com/asgardeo/thunder/internal/identity/oauth2/granthandlers"
2929
"github.com/asgardeo/thunder/internal/identity/oauth2/model"
30-
"github.com/asgardeo/thunder/internal/system/config"
3130
"github.com/asgardeo/thunder/internal/system/log"
3231
"github.com/asgardeo/thunder/internal/utils"
3332

3433
"go.uber.org/zap"
3534
)
3635

37-
type TokenHandler struct {
38-
Config *config.Config
39-
}
36+
type TokenHandler struct{}
4037

4138
// HandleTokenRequest handles the token request for OAuth 2.0.
4239
// It validates the client credentials and delegates to the appropriate grant handler.
@@ -119,7 +116,7 @@ func (th *TokenHandler) HandleTokenRequest(respWriter http.ResponseWriter, reque
119116
}
120117

121118
// Retrieve the OAuth application based on the client Id.
122-
appProvider := appprovider.NewApplicationProvider(th.Config)
119+
appProvider := appprovider.NewApplicationProvider()
123120
appService := appProvider.GetApplicationService()
124121

125122
oauthApp, err := appService.GetOAuthApplication(clientId)

0 commit comments

Comments
 (0)