util.go (635B)
1 package manage 2 3 import ( 4 "net/url" 5 "strings" 6 7 "github.com/superseriousbusiness/oauth2/v4/errors" 8 ) 9 10 type ( 11 // ValidateURIHandler validates that redirectURI is contained in baseURI 12 ValidateURIHandler func(baseURI, redirectURI string) error 13 ) 14 15 // DefaultValidateURI validates that redirectURI is contained in baseURI 16 func DefaultValidateURI(baseURI string, redirectURI string) error { 17 base, err := url.Parse(baseURI) 18 if err != nil { 19 return err 20 } 21 22 redirect, err := url.Parse(redirectURI) 23 if err != nil { 24 return err 25 } 26 if !strings.HasSuffix(redirect.Host, base.Host) { 27 return errors.ErrInvalidRedirectURI 28 } 29 return nil 30 }