mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-17 21:32:55 +01:00
rename auth-related fields on WebSocket struct.
This commit is contained in:
parent
888ac8c1c0
commit
84d01dc1d3
10
handlers.go
10
handlers.go
@ -44,9 +44,9 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
rand.Read(challenge)
|
||||
|
||||
ws := &WebSocket{
|
||||
conn: conn,
|
||||
Challenge: hex.EncodeToString(challenge),
|
||||
WaitingForAuth: make(chan struct{}),
|
||||
conn: conn,
|
||||
Challenge: hex.EncodeToString(challenge),
|
||||
Authed: make(chan struct{}),
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, WS_KEY, ws)
|
||||
@ -177,8 +177,8 @@ func (rl *Relay) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
|
||||
case *nostr.AuthEnvelope:
|
||||
if rl.ServiceURL != "" {
|
||||
if pubkey, ok := nip42.ValidateAuthEvent(&env.Event, ws.Challenge, rl.ServiceURL); ok {
|
||||
ws.Authed = pubkey
|
||||
close(ws.WaitingForAuth)
|
||||
ws.AuthedPublicKey = pubkey
|
||||
close(ws.Authed)
|
||||
ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, pubkey)
|
||||
ws.WriteJSON(nostr.OKEnvelope{EventID: env.Event.ID, OK: true})
|
||||
} else {
|
||||
|
@ -11,9 +11,9 @@ type WebSocket struct {
|
||||
mutex sync.Mutex
|
||||
|
||||
// nip42
|
||||
Challenge string
|
||||
Authed string
|
||||
WaitingForAuth chan struct{}
|
||||
Challenge string
|
||||
AuthedPublicKey string
|
||||
Authed chan struct{}
|
||||
}
|
||||
|
||||
func (ws *WebSocket) WriteJSON(any any) error {
|
||||
|
Loading…
x
Reference in New Issue
Block a user