mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-07 05:34:38 +08:00
remove need of frontend url for error pages
This commit is contained in:
parent
6d54851ed4
commit
1a442aa299
7 changed files with 25 additions and 31 deletions
|
@ -37,16 +37,13 @@ func initAzureAD(redirectURL string, clientID string, clientSecret string) {
|
|||
|
||||
func handleAzureLogin(w http.ResponseWriter, r *http.Request) {
|
||||
var oauth_state_string = logic.RandomString(user_signin_length)
|
||||
if auth_provider == nil && servercfg.GetFrontendURL() != "" {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
return
|
||||
} else if auth_provider == nil {
|
||||
fmt.Fprintf(w, "%s", []byte("no frontend URL was provided and an OAuth login was attempted\nplease reconfigure server to use OAuth or use basic credentials"))
|
||||
if auth_provider == nil {
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
if err := logic.SetState(oauth_state_string); err != nil {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -60,7 +57,7 @@ func handleAzureCallback(w http.ResponseWriter, r *http.Request) {
|
|||
var content, err = getAzureUserInfo(rState, rCode)
|
||||
if err != nil {
|
||||
logger.Log(1, "error when getting user info from azure:", err.Error())
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.UserPrincipalName)
|
||||
|
|
|
@ -37,16 +37,13 @@ func initGithub(redirectURL string, clientID string, clientSecret string) {
|
|||
|
||||
func handleGithubLogin(w http.ResponseWriter, r *http.Request) {
|
||||
var oauth_state_string = logic.RandomString(user_signin_length)
|
||||
if auth_provider == nil && servercfg.GetFrontendURL() != "" {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
return
|
||||
} else if auth_provider == nil {
|
||||
fmt.Fprintf(w, "%s", []byte("no frontend URL was provided and an OAuth login was attempted\nplease reconfigure server to use OAuth or use basic credentials"))
|
||||
if auth_provider == nil {
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
if err := logic.SetState(oauth_state_string); err != nil {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -60,7 +57,7 @@ func handleGithubCallback(w http.ResponseWriter, r *http.Request) {
|
|||
var content, err = getGithubUserInfo(rState, rCode)
|
||||
if err != nil {
|
||||
logger.Log(1, "error when getting user info from github:", err.Error())
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.Login)
|
||||
|
|
|
@ -38,16 +38,13 @@ func initGoogle(redirectURL string, clientID string, clientSecret string) {
|
|||
|
||||
func handleGoogleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
var oauth_state_string = logic.RandomString(user_signin_length)
|
||||
if auth_provider == nil && servercfg.GetFrontendURL() != "" {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
return
|
||||
} else if auth_provider == nil {
|
||||
fmt.Fprintf(w, "%s", []byte("no frontend URL was provided and an OAuth login was attempted\nplease reconfigure server to use OAuth or use basic credentials"))
|
||||
if auth_provider == nil {
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
if err := logic.SetState(oauth_state_string); err != nil {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -62,7 +59,7 @@ func handleGoogleCallback(w http.ResponseWriter, r *http.Request) {
|
|||
var content, err = getGoogleUserInfo(rState, rCode)
|
||||
if err != nil {
|
||||
logger.Log(1, "error when getting user info from google:", err.Error())
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.Email)
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/gravitl/netmaker/logic/pro/netcache"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
"github.com/gravitl/netmaker/models/promodels"
|
||||
"github.com/gravitl/netmaker/servercfg"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -41,7 +40,7 @@ func HandleNodeSSOCallback(w http.ResponseWriter, r *http.Request) {
|
|||
var userClaims, err = functions[get_user_info].(func(string, string) (*OAuthUser, error))(state, code)
|
||||
if err != nil {
|
||||
logger.Log(0, "error when getting user info from callback:", err.Error())
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
11
auth/oidc.go
11
auth/oidc.go
|
@ -50,16 +50,13 @@ func initOIDC(redirectURL string, clientID string, clientSecret string, issuer s
|
|||
|
||||
func handleOIDCLogin(w http.ResponseWriter, r *http.Request) {
|
||||
var oauth_state_string = logic.RandomString(user_signin_length)
|
||||
if auth_provider == nil && servercfg.GetFrontendURL() != "" {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
return
|
||||
} else if auth_provider == nil {
|
||||
fmt.Fprintf(w, "%s", []byte("no frontend URL was provided and an OAuth login was attempted\nplease reconfigure server to use OAuth or use basic credentials"))
|
||||
if auth_provider == nil {
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
|
||||
if err := logic.SetState(oauth_state_string); err != nil {
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
var url = auth_provider.AuthCodeURL(oauth_state_string)
|
||||
|
@ -73,7 +70,7 @@ func handleOIDCCallback(w http.ResponseWriter, r *http.Request) {
|
|||
var content, err = getOIDCUserInfo(rState, rCode)
|
||||
if err != nil {
|
||||
logger.Log(1, "error when getting user info from callback:", err.Error())
|
||||
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||
logic.HandleOauthNotConfigured(w)
|
||||
return
|
||||
}
|
||||
_, err = logic.GetUser(content.Email)
|
||||
|
|
|
@ -20,7 +20,7 @@ import (
|
|||
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "netmaker",
|
||||
Use: "nmctl",
|
||||
Short: "CLI for interacting with Netmaker Server",
|
||||
Long: `CLI for interacting with Netmaker Server`,
|
||||
// Uncomment the following line if your bare application
|
||||
|
|
|
@ -56,3 +56,10 @@ func ReturnErrorResponse(response http.ResponseWriter, request *http.Request, er
|
|||
response.WriteHeader(errorMessage.Code)
|
||||
response.Write(jsonResponse)
|
||||
}
|
||||
|
||||
// HandleOauthNotConfigured - returns an appropriate html page when oauth is not configured on netmaker server but an oauth login was attempted
|
||||
func HandleOauthNotConfigured(response http.ResponseWriter) {
|
||||
response.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
response.WriteHeader(http.StatusInternalServerError)
|
||||
response.Write([]byte("<html><body><h1>OAuth Login Failed, check if server is configured for OAuth.</h1></body></html>"))
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue