forked from
willdot.net/cocoon
A fork of the Cocoon PDS but being made more distributed.
1package client
2
3import (
4 "net/url"
5
6 "github.com/lestrrat-go/jwx/v2/jwk"
7)
8
9type Client struct {
10 Metadata *Metadata
11 JWKS jwk.Key
12 IsLocalhostClient bool
13}
14
15func (c *Client) IsRedirectURIAllowed(requestedURI string) bool {
16 if c.IsLocalhostClient {
17 ru, err := url.Parse(requestedURI)
18 if err != nil || ru.Scheme != "http" || !isLoopbackHost(ru.Hostname()) {
19 return false
20 }
21 for _, registered := range c.Metadata.RedirectURIs {
22 reg, err := url.Parse(registered)
23 if err != nil {
24 continue
25 }
26 if reg.Hostname() == ru.Hostname() && reg.Path == ru.Path {
27 return true
28 }
29 }
30 return false
31 }
32 for _, uri := range c.Metadata.RedirectURIs {
33 if uri == requestedURI {
34 return true
35 }
36 }
37 return false
38}