Revert changes to auth server code
This commit is contained in:
parent
fc7a7b1799
commit
be89fb7dd9
1 changed files with 29 additions and 57 deletions
|
@ -15,63 +15,20 @@ type Handler struct {
|
||||||
key, secret string
|
key, secret string
|
||||||
}
|
}
|
||||||
|
|
||||||
type OpenIDTokenType struct {
|
|
||||||
}
|
|
||||||
|
|
||||||
type SFURequest struct {
|
|
||||||
Room string `json:"room"`
|
|
||||||
OpenIDToken OpenIDTokenType `json:"openid_token"`
|
|
||||||
DeviceID string `json:"device_id"`
|
|
||||||
RemoveMeUserID string `json:"remove_me_user_id"` // we'll get this from OIDC
|
|
||||||
}
|
|
||||||
|
|
||||||
type SFUResponse struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
JWT string `json:"jwt"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *Handler) handle(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) handle(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Printf("Request from %s", r.RemoteAddr)
|
log.Printf("Request from %s", r.RemoteAddr)
|
||||||
|
|
||||||
// Set the CORS headers
|
// Set the CORS headers
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "POST")
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token")
|
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
|
||||||
|
|
||||||
// Handle preflight request (CORS)
|
// Handle preflight request (CORS)
|
||||||
if r.Method == "OPTIONS" {
|
if r.Method == "OPTIONS" {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
return
|
return
|
||||||
} else if r.Method == "POST" {
|
|
||||||
var body SFURequest
|
|
||||||
err := json.NewDecoder(r.Body).Decode(&body)
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error decoding JSON: %v", err)
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if body.Room == "" {
|
|
||||||
log.Printf("Request missing room")
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
token, err := getJoinToken(h.key, h.secret, body.Room, body.RemoveMeUserID+":"+body.DeviceID)
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
res := SFUResponse{URL: "http://localhost:7880/", JWT: token}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
json.NewEncoder(w).Encode(res)
|
|
||||||
} else {
|
|
||||||
w.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
roomName := r.URL.Query().Get("roomName")
|
roomName := r.URL.Query().Get("roomName")
|
||||||
name := r.URL.Query().Get("name")
|
name := r.URL.Query().Get("name")
|
||||||
identity := r.URL.Query().Get("identity")
|
identity := r.URL.Query().Get("identity")
|
||||||
|
@ -82,7 +39,17 @@ func (h *Handler) handle(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
token, err := getJoinToken(h.key, h.secret, roomName, identity, name)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res := Response{token}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
json.NewEncoder(w).Encode(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -101,11 +68,15 @@ func main() {
|
||||||
secret: secret,
|
secret: secret,
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/sfu/get", handler.handle)
|
http.HandleFunc("/token", handler.handle)
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
func getJoinToken(apiKey, apiSecret, room, identity string) (string, error) {
|
type Response struct {
|
||||||
|
Token string `json:"accessToken"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func getJoinToken(apiKey, apiSecret, room, identity, name string) (string, error) {
|
||||||
at := auth.NewAccessToken(apiKey, apiSecret)
|
at := auth.NewAccessToken(apiKey, apiSecret)
|
||||||
|
|
||||||
canPublish := true
|
canPublish := true
|
||||||
|
@ -120,7 +91,8 @@ func getJoinToken(apiKey, apiSecret, room, identity string) (string, error) {
|
||||||
|
|
||||||
at.AddGrant(grant).
|
at.AddGrant(grant).
|
||||||
SetIdentity(identity).
|
SetIdentity(identity).
|
||||||
SetValidFor(time.Hour)
|
SetValidFor(time.Hour).
|
||||||
|
SetName(name)
|
||||||
|
|
||||||
return at.ToJWT()
|
return at.ToJWT()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue