Compare commits
2 commits
9e02980415
...
04fb803330
Author | SHA1 | Date | |
---|---|---|---|
04fb803330 | |||
850d0af0bb |
3 changed files with 8 additions and 38 deletions
|
@ -129,11 +129,6 @@ func main() {
|
||||||
http.Redirect(writer, request, redirectURL, http.StatusSeeOther)
|
http.Redirect(writer, request, redirectURL, http.StatusSeeOther)
|
||||||
})
|
})
|
||||||
|
|
||||||
// for tests, can access only with valid token (when logged in)
|
|
||||||
http.HandleFunc("/protected", logic.ValidateToken(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Write([]byte("Hello, I'm protected"))
|
|
||||||
}, srv))
|
|
||||||
|
|
||||||
// can access only with valid token (when logged in), deletes client
|
// can access only with valid token (when logged in), deletes client
|
||||||
http.HandleFunc("/delete", logic.ValidateToken(func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/delete", logic.ValidateToken(func(w http.ResponseWriter, r *http.Request) {
|
||||||
id := r.Header.Get("client_id")
|
id := r.Header.Get("client_id")
|
||||||
|
@ -203,6 +198,11 @@ func main() {
|
||||||
outputHTML(w, r, "static/register.html")
|
outputHTML(w, r, "static/register.html")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// can access only with valid token (when logged in)
|
||||||
|
http.HandleFunc("/verify", logic.ValidateToken(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
}, srv))
|
||||||
|
|
||||||
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(config.AuthServerPort), nil))
|
log.Fatal(http.ListenAndServe(":"+strconv.Itoa(config.AuthServerPort), nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<body>
|
<body>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1>Sign In</h1>
|
<h1>Sign In</h1>
|
||||||
<form id="loginForm" action="/login" method="GET">
|
<form action="/login" method="GET">
|
||||||
<input type="hidden" name="grant_type" value="client_credentials" />
|
<input type="hidden" name="grant_type" value="client_credentials" />
|
||||||
<input type="hidden" name="scope" value="all" />
|
<input type="hidden" name="scope" value="all" />
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -25,29 +25,10 @@
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-success">Sign In</button>
|
<button type="submit" class="btn btn-success">Sign In</button>
|
||||||
</form>
|
</form>
|
||||||
<form id="registerForm" action="/register.html" method="GET">
|
<form action="/register.html" method="GET">
|
||||||
<button type="submit" class="btn btn-primary">Register</button>
|
<button type="submit" class="btn btn-primary">Register</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
|
||||||
function submitFormWithReferer(formId) {
|
|
||||||
var form = document.getElementById(formId);
|
|
||||||
var referrer = document.referrer || "";
|
|
||||||
form.insertAdjacentHTML('beforeend', '<input type="hidden" name="referer" value="' + referrer + '">');
|
|
||||||
form.submit();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.getElementById("loginForm").addEventListener("submit", function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
submitFormWithReferer("loginForm");
|
|
||||||
});
|
|
||||||
|
|
||||||
document.getElementById("registerForm").addEventListener("submit", function (event) {
|
|
||||||
event.preventDefault();
|
|
||||||
submitFormWithReferer("registerForm");
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -56,4 +37,4 @@
|
||||||
.btn-primary {
|
.btn-primary {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
|
@ -1,11 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8">
|
|
||||||
<title>Redirect</title>
|
|
||||||
<meta http-equiv="refresh" content="0;url=http://localhost:9096/login.html">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<p>If you are not redirected, <a href="http://localhost:9096/login.html">click here</a>.</p>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
Reference in a new issue