fix(openid/client): handle missing redirect uri for callbacks

This commit is contained in:
Trong Huu Nguyen
2022-09-09 12:31:17 +02:00
parent 27d2bc2c26
commit 7f93c62604

View File

@@ -8,6 +8,7 @@ import (
"golang.org/x/oauth2"
urlpkg "github.com/nais/wonderwall/pkg/handler/url"
"github.com/nais/wonderwall/pkg/openid"
)
@@ -23,6 +24,16 @@ func NewLoginCallback(c *Client, r *http.Request, cookie *openid.LoginCookie) (*
return nil, fmt.Errorf("cookie is nil")
}
// redirect_uri not set in cookie (e.g. login initiated at instance running older version, callback handled at newer version)
if len(cookie.RedirectURI) == 0 {
callbackURL, err := urlpkg.LoginCallbackURL(r)
if err != nil {
return nil, fmt.Errorf("generating callback url: %w", err)
}
cookie.RedirectURI = callbackURL
}
return &LoginCallback{
Client: c,
cookie: cookie,