File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,15 @@ func (app *OAuth2Application) TableName() string {
53
53
54
54
// ContainsRedirectURI checks if redirectURI is allowed for app
55
55
func (app * OAuth2Application ) ContainsRedirectURI (redirectURI string ) bool {
56
+ contains := func (s string ) bool {
57
+ s = strings .TrimSuffix (strings .ToLower (s ), "/" )
58
+ for _ , u := range app .RedirectURIs {
59
+ if strings .TrimSuffix (strings .ToLower (u ), "/" ) == s {
60
+ return true
61
+ }
62
+ }
63
+ return false
64
+ }
56
65
if ! app .ConfidentialClient {
57
66
uri , err := url .Parse (redirectURI )
58
67
// ignore port for http loopback uris following https://datatracker.ietf.org/doc/html/rfc8252#section-7.3
@@ -61,13 +70,13 @@ func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
61
70
if ip != nil && ip .IsLoopback () {
62
71
// strip port
63
72
uri .Host = uri .Hostname ()
64
- if util . SliceContainsString ( app . RedirectURIs , uri .String (), true ) {
73
+ if contains ( uri .String ()) {
65
74
return true
66
75
}
67
76
}
68
77
}
69
78
}
70
- return util . SliceContainsString ( app . RedirectURIs , redirectURI , true )
79
+ return contains ( redirectURI )
71
80
}
72
81
73
82
// Base32 characters, but lowercased.
Original file line number Diff line number Diff line change @@ -63,6 +63,18 @@ func TestOAuth2Application_ContainsRedirectURI_WithPort(t *testing.T) {
63
63
assert .False (t , app .ContainsRedirectURI (":" ))
64
64
}
65
65
66
+ func TestOAuth2Application_ContainsRedirect_Slash (t * testing.T ) {
67
+ app := & auth_model.OAuth2Application {RedirectURIs : []string {"http://127.0.0.1" }}
68
+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1" ))
69
+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1/" ))
70
+ assert .False (t , app .ContainsRedirectURI ("http://127.0.0.1/other" ))
71
+
72
+ app = & auth_model.OAuth2Application {RedirectURIs : []string {"http://127.0.0.1/" }}
73
+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1" ))
74
+ assert .True (t , app .ContainsRedirectURI ("http://127.0.0.1/" ))
75
+ assert .False (t , app .ContainsRedirectURI ("http://127.0.0.1/other" ))
76
+ }
77
+
66
78
func TestOAuth2Application_ValidateClientSecret (t * testing.T ) {
67
79
assert .NoError (t , unittest .PrepareTestDatabase ())
68
80
app := unittest .AssertExistsAndLoadBean (t , & auth_model.OAuth2Application {ID : 1 })
You can’t perform that action at this time.
0 commit comments