Skip to content

Don't init oauth if settings have it disabled #31533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions services/auth/source/oauth2/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@

// Init initializes the oauth source
func Init(ctx context.Context) error {
// if oauth is disabled, we don't need to initialize anything
if !setting.OAuth2.Enable {

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / backend

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-sqlite

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-pgsql

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-mssql

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-unit

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-mysql

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / checks-backend

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-e2e

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-backend

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-backend

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-backend

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)

Check failure on line 34 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

setting.OAuth2.Enable undefined (type struct{Enabled bool; AccessTokenExpirationTime int64; RefreshTokenExpirationTime int64; InvalidateRefreshTokens bool; JWTSigningAlgorithm string "ini:\"JWT_SIGNING_ALGORITHM\""; JWTSigningPrivateKeyFile string "ini:\"JWT_SIGNING_PRIVATE_KEY_FILE\""; MaxTokenLength int; DefaultApplications []string} has no field or method Enable)
return

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / backend

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-sqlite

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-pgsql

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-mssql

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-unit

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-mysql

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / checks-backend

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / test-e2e

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-gogit

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-backend

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-backend

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-backend

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

not enough return values

Check failure on line 35 in services/auth/source/oauth2/init.go

View workflow job for this annotation

GitHub Actions / lint-go-windows

not enough return values
}

if err := InitSigningKey(); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions services/auth/source/oauth2/jwtsigningkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ func InitSigningKey() error {
// loadOrCreateAsymmetricKey checks if the configured private key exists.
// If it does not exist a new random key gets generated and saved on the configured path.
func loadOrCreateAsymmetricKey() (any, error) {
if !filepath.IsAbs(setting.OAuth2.JWTSigningPrivateKeyFile) {
setting.OAuth2.JWTSigningPrivateKeyFile = filepath.Join(setting.AppDataPath, setting.OAuth2.JWTSigningPrivateKeyFile)
}

keyPath := setting.OAuth2.JWTSigningPrivateKeyFile

isExist, err := util.IsExist(keyPath)
Expand Down
Loading