2021-09-09 09:00:58 +00:00
|
|
|
package application
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-03-03 09:40:07 +00:00
|
|
|
"goauthentik.io/api/v3"
|
2021-09-09 09:00:58 +00:00
|
|
|
"golang.org/x/oauth2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type OIDCEndpoint struct {
|
|
|
|
oauth2.Endpoint
|
2023-01-13 15:22:03 +00:00
|
|
|
TokenIntrospection string
|
2021-09-09 09:00:58 +00:00
|
|
|
EndSessionEndpoint string
|
2022-01-21 12:29:51 +00:00
|
|
|
JwksUri string
|
2023-01-19 14:39:30 +00:00
|
|
|
Issuer string
|
2021-09-09 09:00:58 +00:00
|
|
|
}
|
|
|
|
|
2023-01-19 14:39:30 +00:00
|
|
|
func updateURL(rawUrl string, scheme string, host string) string {
|
|
|
|
u, err := url.Parse(rawUrl)
|
|
|
|
if err != nil {
|
|
|
|
return rawUrl
|
|
|
|
}
|
|
|
|
u.Host = host
|
|
|
|
u.Scheme = scheme
|
|
|
|
return u.String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetOIDCEndpoint(p api.ProxyOutpostConfig, authentikHost string, embedded bool) OIDCEndpoint {
|
2021-09-09 09:00:58 +00:00
|
|
|
authUrl := p.OidcConfiguration.AuthorizationEndpoint
|
|
|
|
endUrl := p.OidcConfiguration.EndSessionEndpoint
|
2023-01-19 14:39:30 +00:00
|
|
|
tokenUrl := p.OidcConfiguration.TokenEndpoint
|
2022-01-21 12:29:51 +00:00
|
|
|
jwksUrl := p.OidcConfiguration.JwksUri
|
2021-09-26 10:00:51 +00:00
|
|
|
if browserHost, found := os.LookupEnv("AUTHENTIK_HOST_BROWSER"); found && browserHost != "" {
|
2021-09-09 09:00:58 +00:00
|
|
|
host := os.Getenv("AUTHENTIK_HOST")
|
|
|
|
authUrl = strings.ReplaceAll(authUrl, host, browserHost)
|
|
|
|
endUrl = strings.ReplaceAll(endUrl, host, browserHost)
|
2022-01-21 12:29:51 +00:00
|
|
|
jwksUrl = strings.ReplaceAll(jwksUrl, host, browserHost)
|
2021-09-09 09:00:58 +00:00
|
|
|
}
|
|
|
|
ep := OIDCEndpoint{
|
|
|
|
Endpoint: oauth2.Endpoint{
|
|
|
|
AuthURL: authUrl,
|
2023-01-19 14:39:30 +00:00
|
|
|
TokenURL: tokenUrl,
|
2021-09-09 09:00:58 +00:00
|
|
|
AuthStyle: oauth2.AuthStyleInParams,
|
|
|
|
},
|
|
|
|
EndSessionEndpoint: endUrl,
|
2022-01-21 12:29:51 +00:00
|
|
|
JwksUri: jwksUrl,
|
2023-01-14 19:54:34 +00:00
|
|
|
TokenIntrospection: p.OidcConfiguration.IntrospectionEndpoint,
|
2023-01-19 14:39:30 +00:00
|
|
|
Issuer: p.OidcConfiguration.Issuer,
|
2021-09-09 09:00:58 +00:00
|
|
|
}
|
2023-01-19 14:39:30 +00:00
|
|
|
if !embedded {
|
2021-09-09 09:00:58 +00:00
|
|
|
return ep
|
|
|
|
}
|
|
|
|
if authentikHost == "" {
|
|
|
|
log.Warning("Outpost has localhost/blank API Connection but no authentik_host is configured.")
|
|
|
|
return ep
|
|
|
|
}
|
|
|
|
aku, err := url.Parse(authentikHost)
|
|
|
|
if err != nil {
|
|
|
|
return ep
|
|
|
|
}
|
2023-01-19 14:39:30 +00:00
|
|
|
ep.AuthURL = updateURL(authUrl, aku.Scheme, aku.Host)
|
|
|
|
ep.EndSessionEndpoint = updateURL(endUrl, aku.Scheme, aku.Host)
|
|
|
|
ep.JwksUri = updateURL(jwksUrl, aku.Scheme, aku.Host)
|
|
|
|
ep.Issuer = updateURL(ep.Issuer, aku.Scheme, aku.Host)
|
2021-09-09 09:00:58 +00:00
|
|
|
return ep
|
|
|
|
}
|