9
extra.go
9
extra.go
@@ -5,9 +5,12 @@ import "context"
|
|||||||
const AUTH_CONTEXT_KEY = iota
|
const AUTH_CONTEXT_KEY = iota
|
||||||
|
|
||||||
func GetAuthStatus(ctx context.Context) (pubkey string, ok bool) {
|
func GetAuthStatus(ctx context.Context) (pubkey string, ok bool) {
|
||||||
authedPubkey := ctx.Value(AUTH_CONTEXT_KEY)
|
value := ctx.Value(AUTH_CONTEXT_KEY)
|
||||||
if authedPubkey == nil {
|
if value == nil {
|
||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
return authedPubkey.(string), true
|
if ws, ok := value.(*WebSocket); ok {
|
||||||
|
return ws.authed, true
|
||||||
|
}
|
||||||
|
return "", false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -293,7 +293,6 @@ func (s *Server) doAuth(ctx context.Context, ws *WebSocket, request []json.RawMe
|
|||||||
}
|
}
|
||||||
if pubkey, ok := nip42.ValidateAuthEvent(&evt, ws.challenge, auther.ServiceURL()); ok {
|
if pubkey, ok := nip42.ValidateAuthEvent(&evt, ws.challenge, auther.ServiceURL()); ok {
|
||||||
ws.authed = pubkey
|
ws.authed = pubkey
|
||||||
ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, pubkey)
|
|
||||||
ws.WriteJSON(nostr.OKEnvelope{EventID: evt.ID, OK: true})
|
ws.WriteJSON(nostr.OKEnvelope{EventID: evt.ID, OK: true})
|
||||||
} else {
|
} else {
|
||||||
ws.WriteJSON(nostr.OKEnvelope{EventID: evt.ID, OK: false, Reason: "error: failed to authenticate"})
|
ws.WriteJSON(nostr.OKEnvelope{EventID: evt.ID, OK: false, Reason: "error: failed to authenticate"})
|
||||||
@@ -324,6 +323,8 @@ func (s *Server) handleMessage(ctx context.Context, ws *WebSocket, message []byt
|
|||||||
var typ string
|
var typ string
|
||||||
json.Unmarshal(request[0], &typ)
|
json.Unmarshal(request[0], &typ)
|
||||||
|
|
||||||
|
ctx = context.WithValue(ctx, AUTH_CONTEXT_KEY, ws)
|
||||||
|
|
||||||
switch typ {
|
switch typ {
|
||||||
case "EVENT":
|
case "EVENT":
|
||||||
notice = s.doEvent(ctx, ws, request, store)
|
notice = s.doEvent(ctx, ws, request, store)
|
||||||
|
|||||||
Reference in New Issue
Block a user