diff options
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | jwt_mock.go | 30 | ||||
| -rw-r--r-- | src/components/App.js | 4 | ||||
| -rw-r--r-- | src/components/Login.js | 3 |
4 files changed, 37 insertions, 5 deletions
@@ -2,7 +2,10 @@ ## Development setup -Run `soc_collector` and set env var `COLLECTOR_URL`. +Env vars: +- `COLLECTOR_URL` +- `JWT_URL` +- `PER_PAGE` The commit pointed to by the `soc_collector` submodule is compatible with `main` in this repo. diff --git a/jwt_mock.go b/jwt_mock.go new file mode 100644 index 0000000..e4a46f5 --- /dev/null +++ b/jwt_mock.go @@ -0,0 +1,30 @@ +package main + +import ( + "fmt" + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Methods", "GET, OPTIONS, POST, PUT") + w.Header().Set("Access-Control-Allow-Headers", "Authorization") + + if r.Method == "OPTIONS" { + w.WriteHeader(http.StatusNoContent) + return + } + + auth := r.Header.Get("Authorization") + if auth != "Basic dXNyOnB3ZA==" { // btoa("usr:pwd") + w.WriteHeader(http.StatusUnauthorized) + return + } + + fmt.Fprint(w, "{\"access_token\": \"JWT_TOKEN_PLACEHOLDER\"}") + }) + + log.Fatal(http.ListenAndServe(":8080", nil)) +} diff --git a/src/components/App.js b/src/components/App.js index 9ead9c5..636c672 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -56,8 +56,8 @@ class App extends React.Component { clearToken={this.clearToken} /> ); - // if (this.state.token === null) - // return <Login setToken={this.setToken} setError={this.setError} />; + if (this.state.token === null) + return <Login setToken={this.setToken} setError={this.setError} />; return ( <Router> <Header clearToken={this.clearToken} /> diff --git a/src/components/Login.js b/src/components/Login.js index 209871e..9b45817 100644 --- a/src/components/Login.js +++ b/src/components/Login.js @@ -26,8 +26,7 @@ class Login extends React.Component { // NOTE: btoa() limits email, password to ASCII login(email, password) { - const url = process.env.JWT_URL + "/api/v1.0/auth"; - fetch(url, { + fetch(process.env.JWT_URL, { method: "POST", headers: { Authorization: "Basic " + btoa(email + ":" + password) } }) |
