mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-16 22:01:19 +08:00
fixed minor bug surrounding oauth error
This commit is contained in:
16
auth/auth.go
16
auth/auth.go
@@ -3,6 +3,7 @@ package auth
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gravitl/netmaker/logic"
|
"github.com/gravitl/netmaker/logic"
|
||||||
@@ -65,6 +66,11 @@ func InitializeAuthProvider() string {
|
|||||||
|
|
||||||
// HandleAuthCallback - handles oauth callback
|
// HandleAuthCallback - handles oauth callback
|
||||||
func HandleAuthCallback(w http.ResponseWriter, r *http.Request) {
|
func HandleAuthCallback(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if auth_provider == nil {
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
fmt.Fprintln(w, oauthNotConfigured)
|
||||||
|
return
|
||||||
|
}
|
||||||
var functions = getCurrentAuthFunctions()
|
var functions = getCurrentAuthFunctions()
|
||||||
if functions == nil {
|
if functions == nil {
|
||||||
return
|
return
|
||||||
@@ -74,6 +80,16 @@ func HandleAuthCallback(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// HandleAuthLogin - handles oauth login
|
// HandleAuthLogin - handles oauth login
|
||||||
func HandleAuthLogin(w http.ResponseWriter, r *http.Request) {
|
func HandleAuthLogin(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if auth_provider == nil {
|
||||||
|
var referer = r.Header.Get("referer")
|
||||||
|
if referer != "" {
|
||||||
|
http.Redirect(w, r, referer+"?oauth=callback-error", http.StatusTemporaryRedirect)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
fmt.Fprintln(w, oauthNotConfigured)
|
||||||
|
return
|
||||||
|
}
|
||||||
var functions = getCurrentAuthFunctions()
|
var functions = getCurrentAuthFunctions()
|
||||||
if functions == nil {
|
if functions == nil {
|
||||||
return
|
return
|
||||||
|
10
auth/error.go
Normal file
10
auth/error.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package auth
|
||||||
|
|
||||||
|
// == define error HTML here ==
|
||||||
|
const oauthNotConfigured = `<!DOCTYPE html><html>
|
||||||
|
<body>
|
||||||
|
<h3>Your Netmaker server does not have OAuth configured.</h3>
|
||||||
|
<p>Please visit the docs <a href="https://docs.netmaker.org/oauth.html" target="_blank" rel="noopener">here</a> to learn how to.</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
@@ -29,11 +29,6 @@ func userHandlers(r *mux.Router) {
|
|||||||
r.HandleFunc("/api/users", authorizeUserAdm(http.HandlerFunc(getUsers))).Methods("GET")
|
r.HandleFunc("/api/users", authorizeUserAdm(http.HandlerFunc(getUsers))).Methods("GET")
|
||||||
r.HandleFunc("/api/oauth/login", auth.HandleAuthLogin).Methods("GET")
|
r.HandleFunc("/api/oauth/login", auth.HandleAuthLogin).Methods("GET")
|
||||||
r.HandleFunc("/api/oauth/callback", auth.HandleAuthCallback).Methods("GET")
|
r.HandleFunc("/api/oauth/callback", auth.HandleAuthCallback).Methods("GET")
|
||||||
r.HandleFunc("/api/oauth/error", throwOauthError).Methods("GET")
|
|
||||||
}
|
|
||||||
|
|
||||||
func throwOauthError(response http.ResponseWriter, request *http.Request) {
|
|
||||||
returnErrorResponse(response, request, formatError(errors.New("No token returned"), "unauthorized"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node authenticates using its password and retrieves a JWT for authorization.
|
// Node authenticates using its password and retrieves a JWT for authorization.
|
||||||
|
Reference in New Issue
Block a user