Skip to content

Commit

Permalink
Allow sdk redirect url based on schema authgear#3813
Browse files Browse the repository at this point in the history
  • Loading branch information
IniZio committed Feb 23, 2024
1 parent ab8fa9d commit 1e671f9
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions pkg/auth/webapp/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package webapp

import (
"net/http"
"net/url"

"github.com/authgear/authgear-server/pkg/lib/config"
"github.com/authgear/authgear-server/pkg/util/httputil"
)

var reservedRedirectURIs = []string{
"authgearsdk://host/path", // For Authgear SDK only, used for closing the webview
var reservedRedirectURIShemas = []string{
"authgearsdk", // For Authgear SDK only, currently used for closing the webview
}

func GetRedirectURI(r *http.Request, trustProxy bool, defaultURI string) string {
Expand Down Expand Up @@ -36,8 +37,17 @@ func DeriveSettingsRedirectURIFromRequest(r *http.Request, defaultURI string) st
redirectURI := r.URL.Query().Get("redirect_uri")
allowed := false

for _, u := range reservedRedirectURIs {
if u == redirectURI {
parsedRedirectURI, err := url.Parse(redirectURI)
if err != nil {
return ""
}

for _, schema := range reservedRedirectURIShemas {
if err != nil {

Check failure on line 46 in pkg/auth/webapp/redirect.go

View workflow job for this annotation

GitHub Actions / authgear-test

nilness: impossible condition: nil != nil (govet)
panic(err)
}

if parsedRedirectURI.Scheme == schema {
allowed = true
break
}
Expand Down Expand Up @@ -80,10 +90,21 @@ func DerivePostLoginRedirectURIFromRequest(r *http.Request, clientResolver OAuth
return ""
}

allowedURIs := client.RedirectURIs
parsedRedirectURI, err := url.Parse(redirectURI)
if err != nil {
return ""
}

allowed := false

for _, u := range append(reservedRedirectURIs, allowedURIs...) {
for _, shema := range reservedRedirectURIShemas {
if parsedRedirectURI.Scheme == shema {
allowed = true
break
}
}

for _, u := range client.RedirectURIs {
if u == redirectURI {
allowed = true
break
Expand Down

0 comments on commit 1e671f9

Please sign in to comment.