mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-19 19:17:01 -07:00
Fixed IDP endpoint overrides not working correctly
This commit is contained in:
parent
67683e9fca
commit
e940dc2dd9
5 changed files with 29 additions and 18 deletions
|
|
@ -22,7 +22,7 @@ var serveCmd = &cobra.Command{
|
||||||
s := opaal.NewServerWithConfig(&config)
|
s := opaal.NewServerWithConfig(&config)
|
||||||
// FIXME: change how the server address is set with `NewServerWithConfig`
|
// FIXME: change how the server address is set with `NewServerWithConfig`
|
||||||
s.Server.Addr = fmt.Sprintf("%s:%d", s.Issuer.Host, s.Issuer.Port)
|
s.Server.Addr = fmt.Sprintf("%s:%d", s.Issuer.Host, s.Issuer.Port)
|
||||||
err := s.StartIdentityProvider(endpoints)
|
err := s.StartIdentityProvider()
|
||||||
if errors.Is(err, http.ErrServerClosed) {
|
if errors.Is(err, http.ErrServerClosed) {
|
||||||
fmt.Printf("Identity provider server closed.\n")
|
fmt.Printf("Identity provider server closed.\n")
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package opaal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"davidallendj/opaal/internal/oauth"
|
"davidallendj/opaal/internal/oauth"
|
||||||
|
"davidallendj/opaal/internal/oidc"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
@ -72,11 +73,18 @@ type Config struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() Config {
|
func NewConfig() Config {
|
||||||
return Config{
|
config := Config{
|
||||||
Version: goutil.GetCommit(),
|
Version: goutil.GetCommit(),
|
||||||
Server: server.Server{
|
Server: server.Server{
|
||||||
Host: "127.0.0.1",
|
Host: "127.0.0.1",
|
||||||
Port: 3333,
|
Port: 3333,
|
||||||
|
Issuer: server.IdentityProviderServer{
|
||||||
|
Endpoints: oidc.Endpoints{
|
||||||
|
Authorization: "http://127.0.0.1/oauth/authorize",
|
||||||
|
Token: "http://127.0.0.1/oauth/token",
|
||||||
|
JwksUri: "http://127.0.0.1/.well-known/jwks.json",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Options: Options{
|
Options: Options{
|
||||||
RunOnce: true,
|
RunOnce: true,
|
||||||
|
|
@ -99,6 +107,7 @@ func NewConfig() Config {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadConfig(path string) Config {
|
func LoadConfig(path string) Config {
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ func NewServerWithConfig(conf *Config) *server.Server {
|
||||||
Issuer: server.IdentityProviderServer{
|
Issuer: server.IdentityProviderServer{
|
||||||
Host: conf.Server.Issuer.Host,
|
Host: conf.Server.Issuer.Host,
|
||||||
Port: conf.Server.Issuer.Port,
|
Port: conf.Server.Issuer.Port,
|
||||||
|
Endpoints: conf.Server.Issuer.Endpoints,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return server
|
return server
|
||||||
|
|
|
||||||
|
|
@ -171,18 +171,19 @@ func (p *IdentityProvider) UpdateEndpoints(other *IdentityProvider) {
|
||||||
|
|
||||||
func UpdateEndpoints(eps *Endpoints, other *Endpoints) {
|
func UpdateEndpoints(eps *Endpoints, other *Endpoints) {
|
||||||
// only update endpoints that are not empty
|
// only update endpoints that are not empty
|
||||||
var UpdateIf = func(ep *string, s string) {
|
var UpdateIfEmpty = func(ep *string, s string) {
|
||||||
if ep != nil {
|
if ep != nil {
|
||||||
if *ep != "" {
|
if *ep == "" {
|
||||||
*ep = s
|
*ep = s
|
||||||
|
fmt.Printf("updated %s\n", s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
UpdateIf(&eps.Config, other.Config)
|
UpdateIfEmpty(&eps.Config, other.Config)
|
||||||
UpdateIf(&eps.Authorization, other.Authorization)
|
UpdateIfEmpty(&eps.Authorization, other.Authorization)
|
||||||
UpdateIf(&eps.Token, other.Token)
|
UpdateIfEmpty(&eps.Token, other.Token)
|
||||||
UpdateIf(&eps.Revocation, other.Revocation)
|
UpdateIfEmpty(&eps.Revocation, other.Revocation)
|
||||||
UpdateIf(&eps.Introspection, other.Introspection)
|
UpdateIfEmpty(&eps.Introspection, other.Introspection)
|
||||||
UpdateIf(&eps.UserInfo, other.UserInfo)
|
UpdateIfEmpty(&eps.UserInfo, other.UserInfo)
|
||||||
UpdateIf(&eps.JwksUri, other.JwksUri)
|
UpdateIfEmpty(&eps.JwksUri, other.JwksUri)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import (
|
||||||
"github.com/lestrrat-go/jwx/v2/jwt"
|
"github.com/lestrrat-go/jwx/v2/jwt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Server) StartIdentityProvider(eps oidc.Endpoints) error {
|
func (s *Server) StartIdentityProvider() error {
|
||||||
// NOTE: this example does NOT implement CSRF tokens nor use them
|
// NOTE: this example does NOT implement CSRF tokens nor use them
|
||||||
|
|
||||||
// create an example identity provider
|
// create an example identity provider
|
||||||
|
|
@ -44,7 +44,7 @@ func (s *Server) StartIdentityProvider(eps oidc.Endpoints) error {
|
||||||
Token: "http://" + s.Addr + "/oauth/token",
|
Token: "http://" + s.Addr + "/oauth/token",
|
||||||
JwksUri: "http://" + s.Addr + "/.well-known/jwks.json",
|
JwksUri: "http://" + s.Addr + "/.well-known/jwks.json",
|
||||||
}
|
}
|
||||||
oidc.UpdateEndpoints(&eps, &defaultEps)
|
oidc.UpdateEndpoints(&s.Issuer.Endpoints, &defaultEps)
|
||||||
|
|
||||||
// generate key pair used to sign JWKS and create JWTs
|
// generate key pair used to sign JWKS and create JWTs
|
||||||
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
|
||||||
|
|
@ -84,9 +84,9 @@ func (s *Server) StartIdentityProvider(eps oidc.Endpoints) error {
|
||||||
// create config JSON to serve with GET request
|
// create config JSON to serve with GET request
|
||||||
config := map[string]any{
|
config := map[string]any{
|
||||||
"issuer": "http://" + s.Addr,
|
"issuer": "http://" + s.Addr,
|
||||||
"authorization_endpoint": eps.Authorization,
|
"authorization_endpoint": s.Issuer.Endpoints.Authorization,
|
||||||
"token_endpoint": eps.Token,
|
"token_endpoint": s.Issuer.Endpoints.Token,
|
||||||
"jwks_uri": eps.JwksUri,
|
"jwks_uri": s.Issuer.Endpoints.JwksUri,
|
||||||
"scopes_supported": []string{
|
"scopes_supported": []string{
|
||||||
"openid",
|
"openid",
|
||||||
"profile",
|
"profile",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue