mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-28 18:51:53 +01:00
trim trailing slash from expected and found relay URL, clean up
This commit is contained in:
parent
c816103774
commit
443c7cf633
@ -2,6 +2,7 @@ package nip42
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/nbd-wtf/go-nostr"
|
"github.com/nbd-wtf/go-nostr"
|
||||||
@ -41,16 +42,20 @@ func ValidateAuthEvent(event *nostr.Event, challenge string, relayURL string) (p
|
|||||||
return "", false
|
return "", false
|
||||||
}
|
}
|
||||||
|
|
||||||
expected, err1 := url.Parse(relayURL)
|
expected, err := url.Parse(strings.TrimSuffix(relayURL, "/"))
|
||||||
found, err2 := url.Parse(event.Tags.GetFirst([]string{"relay", ""}).Value())
|
if err != nil {
|
||||||
if err1 != nil || err2 != nil {
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
found, err := url.Parse(strings.TrimSuffix(event.Tags.GetFirst([]string{"relay", ""}).Value(), "/"))
|
||||||
|
if err != nil {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
|
||||||
|
if expected.Scheme != found.Scheme ||
|
||||||
|
expected.Host != found.Host ||
|
||||||
|
expected.Path != found.Path {
|
||||||
return "", false
|
return "", false
|
||||||
} else {
|
|
||||||
if expected.Scheme != found.Scheme ||
|
|
||||||
expected.Host != found.Host ||
|
|
||||||
expected.Path != found.Path {
|
|
||||||
return "", false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return event.PubKey, true
|
return event.PubKey, true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user