mirror of
https://github.com/JuLi0n21/pwa-player.git
synced 2026-04-19 15:30:05 +00:00
basic oauth validation added
This commit is contained in:
@@ -4,26 +4,34 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func run() error {
|
||||
|
||||
port := os.Getenv("PORT")
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/me", AuthMiddleware(http.HandlerFunc(MeHandler)))
|
||||
mux.Handle("/login", http.HandlerFunc(LoginRedirect))
|
||||
|
||||
fmt.Println("Starting Server on :42000")
|
||||
mux.Handle("/oauth/code", http.HandlerFunc(Oauth))
|
||||
|
||||
fmt.Println("Starting Server on", port)
|
||||
|
||||
//global middleware
|
||||
handler := CookieMiddleware(mux)
|
||||
|
||||
return http.ListenAndServe(":42000", handler)
|
||||
return http.ListenAndServe(port, handler)
|
||||
}
|
||||
|
||||
func MeHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
user := r.Context().Value("user").(*User)
|
||||
|
||||
//mask token...
|
||||
user.Token = Token{}
|
||||
|
||||
w.Header().Set("Content-Type", "application/Json")
|
||||
|
||||
JSONResponse(w, http.StatusOK, user)
|
||||
|
||||
Reference in New Issue
Block a user