Skip to content

Commit

Permalink
Added an "OK" signal when authenticated (or not)
Browse files Browse the repository at this point in the history
To interact with okCallback in go-nostr relay.go.
  • Loading branch information
barkyq committed Jan 16, 2023
1 parent c573c46 commit cf3f94f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) {
s.clients[conn] = struct{}{}
ticker := time.NewTicker(pingPeriod)

// nip-42 challenge
// NIP-42 challenge
challenge := make([]byte, 8)
rand.Read(challenge)

Expand Down Expand Up @@ -82,7 +82,7 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) {
return nil
})

// nip42 auth challenge
// NIP-42 auth challenge
if _, ok := s.relay.(Auther); ok {
ws.WriteJSON([]interface{}{"AUTH", ws.challenge})
}
Expand Down Expand Up @@ -260,6 +260,9 @@ func (s *Server) handleWebsocket(w http.ResponseWriter, r *http.Request) {
}
if pubkey, ok := nip42.ValidateAuthEvent(&evt, ws.challenge, auther.ServiceURL()); ok {
ws.authed = pubkey
ws.WriteJSON([]interface{}{"OK", evt.ID, true, "authentication success"})
} else {
ws.WriteJSON([]interface{}{"OK", evt.ID, false, "error: failed to authenticate"})
}
}
default:
Expand Down

0 comments on commit cf3f94f

Please sign in to comment.