-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
59 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
HOST=localhost | ||
PORT=8080 | ||
ALLOWED_ORIGINS=http://localhost:8080 | ||
ALLOWED_ORIGINS=http://localhost:8080 | ||
AUTH_PROVIDER=none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package server | ||
|
||
import ( | ||
"net/http" | ||
"strings" | ||
|
||
"github.com/xray-web/web-check-api/config" | ||
) | ||
|
||
type User struct { | ||
ID string | ||
Email string | ||
Name string | ||
Roles []string | ||
} | ||
|
||
type Auth struct { | ||
conf config.Config | ||
// connection / sdk to auth provider, to trade token for user session token | ||
} | ||
|
||
func NewAuth(conf config.Config) *Auth { | ||
// TODO: reduce scope of conf when we know what auth provider we will use | ||
return &Auth{conf: conf} | ||
} | ||
|
||
func (a *Auth) Authenticate(h http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
if a.conf.AuthProvider == "none" { | ||
h.ServeHTTP(w, r) | ||
return | ||
} | ||
authHeader := r.Header.Get("Authorization") | ||
// expect "Bearer token" format | ||
parts := strings.Split(authHeader, " ") | ||
if len(parts) != 2 || parts[0] != "Bearer" { | ||
w.WriteHeader(http.StatusUnauthorized) | ||
return | ||
} | ||
// use token to get user ID from auth provider | ||
// TODO: swap token for user session token | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters