File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Expand file tree Collapse file tree 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 {
5353
5454// ContainsRedirectURI checks if redirectURI is allowed for app
5555func (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+ }
5665 if ! app .ConfidentialClient {
5766 uri , err := url .Parse (redirectURI )
5867 // 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 {
6170 if ip != nil && ip .IsLoopback () {
6271 // strip port
6372 uri .Host = uri .Hostname ()
64- if util . SliceContainsString ( app . RedirectURIs , uri .String (), true ) {
73+ if contains ( uri .String ()) {
6574 return true
6675 }
6776 }
6877 }
6978 }
70- return util . SliceContainsString ( app . RedirectURIs , redirectURI , true )
79+ return contains ( redirectURI )
7180}
7281
7382// 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) {
6363 assert .False (t , app .ContainsRedirectURI (":" ))
6464}
6565
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+
6678func TestOAuth2Application_ValidateClientSecret (t * testing.T ) {
6779 assert .NoError (t , unittest .PrepareTestDatabase ())
6880 app := unittest .AssertExistsAndLoadBean (t , & auth_model.OAuth2Application {ID : 1 })
You can’t perform that action at this time.
0 commit comments