OAuth: Add custom unauthorized message option in configuration (#93717)
* read custom message from config * Read error key from bootdata * oopsie * Remove console.log * Update docs and sample/default inis * Add default key value to the config
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/errutil"
|
||||
"github.com/grafana/grafana/pkg/infra/metrics"
|
||||
"github.com/grafana/grafana/pkg/middleware/cookies"
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
@@ -21,8 +20,7 @@ func (hs *HTTPServer) OAuthLogin(reqCtx *contextmodel.ReqContext) {
|
||||
if errorParam := reqCtx.Query("error"); errorParam != "" {
|
||||
errorDesc := reqCtx.Query("error_description")
|
||||
hs.log.Error("failed to login ", "error", errorParam, "errorDesc", errorDesc)
|
||||
|
||||
hs.redirectWithError(reqCtx, errors.New("login provider denied login request"), "error", errorParam, "errorDesc", errorDesc)
|
||||
hs.redirectWithError(reqCtx, errutil.Unauthorized("oauth.login", errutil.WithPublicMessage(hs.Cfg.OAuthLoginErrorMessage)).Errorf("Login provider denied login request"))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -263,6 +263,7 @@ type Cfg struct {
|
||||
|
||||
// OAuth
|
||||
OAuthAutoLogin bool
|
||||
OAuthLoginErrorMessage string
|
||||
OAuthCookieMaxAge int
|
||||
OAuthAllowInsecureEmailLookup bool
|
||||
OAuthRefreshTokenServerLockMinWaitMs int64
|
||||
@@ -1621,6 +1622,8 @@ func readAuthSettings(iniFile *ini.File, cfg *Cfg) (err error) {
|
||||
cfg.Logger.Warn("[Deprecated] The oauth_auto_login configuration setting is deprecated. Please use auto_login inside auth provider section instead.")
|
||||
}
|
||||
|
||||
// Default to the translation key used in the frontend
|
||||
cfg.OAuthLoginErrorMessage = valueAsString(auth, "oauth_login_error_message", "oauth.login.error")
|
||||
cfg.OAuthCookieMaxAge = auth.Key("oauth_state_cookie_max_age").MustInt(600)
|
||||
cfg.OAuthRefreshTokenServerLockMinWaitMs = auth.Key("oauth_refresh_token_server_lock_min_wait_ms").MustInt64(1000)
|
||||
cfg.SignoutRedirectUrl = valueAsString(auth, "signout_redirect_url", "")
|
||||
|
||||
Reference in New Issue
Block a user