Skip to content
Open
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
28 changes: 14 additions & 14 deletions model/custom_oauth_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ import (

// CustomOAuthProvider stores configuration for custom OAuth providers
type CustomOAuthProvider struct {
Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"type:varchar(64);not null"` // Display name, e.g., "GitHub Enterprise"
Slug string `json:"slug" gorm:"type:varchar(64);uniqueIndex;not null"` // URL identifier, e.g., "github-enterprise"
Enabled bool `json:"enabled" gorm:"default:false"` // Whether this provider is enabled
ClientId string `json:"client_id" gorm:"type:varchar(256)"` // OAuth client ID
ClientSecret string `json:"-" gorm:"type:varchar(512)"` // OAuth client secret (not returned to frontend)
AuthorizationEndpoint string `json:"authorization_endpoint" gorm:"type:varchar(512)"` // Authorization URL
TokenEndpoint string `json:"token_endpoint" gorm:"type:varchar(512)"` // Token exchange URL
UserInfoEndpoint string `json:"user_info_endpoint" gorm:"type:varchar(512)"` // User info URL
Scopes string `json:"scopes" gorm:"type:varchar(256);default:'openid profile email'"` // OAuth scopes
Id int `json:"id" gorm:"primaryKey"`
Name string `json:"name" gorm:"type:varchar(64);not null"` // Display name, e.g., "GitHub Enterprise"
Slug string `json:"slug" gorm:"type:varchar(64);uniqueIndex;not null"` // URL identifier, e.g., "github-enterprise"
Enabled bool `json:"enabled"` // Whether this provider is enabled
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat go.mod | grep -i gorm | head -5

Repository: QuantumNous/new-api

Length of output: 145


🏁 Script executed:

cat -n model/custom_oauth_provider.go

Repository: QuantumNous/new-api

Length of output: 7521


🏁 Script executed:

echo "=== Checking how CustomOAuthProvider is created ===" && \
rg -n --type=go 'CustomOAuthProvider\s*\{' -A 5 | head -50

Repository: QuantumNous/new-api

Length of output: 2222


🏁 Script executed:

echo "=== Checking Create operations for CustomOAuthProvider ===" && \
rg -n --type=go '\.Create\(|NewCustomOAuthProvider' --type=go -B 2 -A 3 | head -60

Repository: QuantumNous/new-api

Length of output: 2534


🏁 Script executed:

echo "=== Checking migrations for CustomOAuthProvider ===" && \
find . -name "*.go" -path "*/migration*" -o -path "*/migrations*" | head -10 && \
rg -n 'CustomOAuthProvider|custom_oauth_provider' --type=go | grep -i "migration\|migrate\|table" | head -20

Repository: QuantumNous/new-api

Length of output: 196


Add not null to the Enabled field for semantic clarity.

The field is currently nullable without a default constraint, which is imprecise for a feature flag. Although the creation code always explicitly sets Enabled, the column definition should enforce this intent with a not null constraint to prevent accidental NULL values if the code path changes:

Suggested fix
-	Enabled               bool   `json:"enabled"`                                                        // Whether this provider is enabled
+	Enabled               bool   `json:"enabled" gorm:"not null;default:false"`                          // Whether this provider is enabled
🤖 Prompt for AI Agents
In `@model/custom_oauth_provider.go` at line 14, The Enabled field in the
CustomOAuthProvider struct is currently nullable; update its GORM/DB struct tag
to include a NOT NULL constraint so the database enforces non-null booleans
(i.e., change the tags on the Enabled field in model/custom_oauth_provider.go to
add `not null`), and ensure any migration or schema generation will pick up the
change so the column is created/altered with NOT NULL to prevent NULL values.

ClientId string `json:"client_id" gorm:"type:varchar(256)"` // OAuth client ID
ClientSecret string `json:"-" gorm:"type:varchar(512)"` // OAuth client secret (not returned to frontend)
AuthorizationEndpoint string `json:"authorization_endpoint" gorm:"type:varchar(512)"` // Authorization URL
TokenEndpoint string `json:"token_endpoint" gorm:"type:varchar(512)"` // Token exchange URL
UserInfoEndpoint string `json:"user_info_endpoint" gorm:"type:varchar(512)"` // User info URL
Scopes string `json:"scopes" gorm:"type:varchar(256);default:'openid profile email'"` // OAuth scopes

// Field mapping configuration (supports JSONPath via gjson)
UserIdField string `json:"user_id_field" gorm:"type:varchar(128);default:'sub'"` // User ID field path, e.g., "sub", "id", "data.user.id"
UsernameField string `json:"username_field" gorm:"type:varchar(128);default:'preferred_username'"` // Username field path
DisplayNameField string `json:"display_name_field" gorm:"type:varchar(128);default:'name'"` // Display name field path
EmailField string `json:"email_field" gorm:"type:varchar(128);default:'email'"` // Email field path
UserIdField string `json:"user_id_field" gorm:"type:varchar(128);default:'sub'"` // User ID field path, e.g., "sub", "id", "data.user.id"
UsernameField string `json:"username_field" gorm:"type:varchar(128);default:'preferred_username'"` // Username field path
DisplayNameField string `json:"display_name_field" gorm:"type:varchar(128);default:'name'"` // Display name field path
EmailField string `json:"email_field" gorm:"type:varchar(128);default:'email'"` // Email field path

// Advanced options
WellKnown string `json:"well_known" gorm:"type:varchar(512)"` // OIDC discovery endpoint (optional)
Expand Down