Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Replace Idp redirectURL in authentication #46

Open
RRebekka opened this issue Aug 7, 2023 · 0 comments
Open

feature: Replace Idp redirectURL in authentication #46

RRebekka opened this issue Aug 7, 2023 · 0 comments

Comments

@RRebekka
Copy link

RRebekka commented Aug 7, 2023

Hi,

I wanted to ask if it would be possible to adjust the hostname of the r.Response.RedirectURL in the authentication method of the identity provider. In my setup I have an OIDC identity provider that is used in the Caddy security module. In the start up, I use the localhost:xxx address in the metadata url for fetching the meta data. Thus, the returned authorizationURL contains localhost as hostname. Later, when the user tries to authenticate themselves, they are redirected to the authorization backend via the localhost address. However, I want that the user is redirected to the authorization backend via the reverse proxied route of the authorization backend setup in Caddy. I can not use the reverse proxied route in the metadata_url, because the domain can change.

I have tested locally with my setup with something like the following, added to the Authenticate function in the idp/oauth/authenticate.go :

`

     var u, err = url.Parse(b.authorizationURL)
     b.logger.Debug("Authorization url")
     b.logger.Debug(b.authorizationURL)
     b.logger.Debug(u.Host)
     b.logger.Debug(u.Hostname())
     if u.Hostname() == "localhost" && err == nil {
	var u_, err_ = url.Parse(r.Upstream.BaseURL)
	if err != nil || err_ != nil {
		b.logger.Debug("Error in replacing url")
		return err
	}
	u.Scheme = "https"
	u.Host = u_.Host

	b.logger.Debug("Replaced url: ")
	b.logger.Debug(u.String())

	r.Response.RedirectURL = u.String() + "?" + params.Encode()
    } else {
	r.Response.RedirectURL = b.authorizationURL + "?" + params.Encode()
    }

`
Do you see any problems with that changes that I currently oversee?

Best regards,
Rebekka

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants