Skip to content

Commit

Permalink
Add disable-identifier-webapp option Kopano-dev#25
Browse files Browse the repository at this point in the history
Allows to use a different identifier-client, for example one served from elsewhere.
  • Loading branch information
IljaN committed Feb 28, 2020
1 parent 77149f5 commit e7082c4
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type Config struct {
IdentifierClientPath string
IdentifierRegistrationConf string
IdentifierScopesConf string
IdentifierWebAppDisabled bool
SigningKid string
SigningMethod string
SigningPrivateKeyFiles []string
Expand All @@ -109,6 +110,7 @@ type bootstrap struct {

issuerIdentifierURI *url.URL
identifierClientPath string
identifierWebAppDisabled bool
identifierRegistrationConf string
identifierAuthoritiesConf string
identifierScopesConf string
Expand Down Expand Up @@ -271,6 +273,7 @@ func (bs *bootstrap) initialize(cfg *Config) error {
bs.cfg.ListenAddr = cfg.Listen

bs.identifierClientPath = cfg.IdentifierClientPath
bs.identifierWebAppDisabled = cfg.IdentifierWebAppDisabled

bs.identifierRegistrationConf = cfg.IdentifierRegistrationConf
if bs.identifierRegistrationConf != "" {
Expand Down
1 change: 1 addition & 0 deletions bootstrap/kc.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ func newKCIdentityManager(bs *bootstrap) (identity.Manager, error) {
StaticFolder: bs.identifierClientPath,
LogonCookieName: "__Secure-KKT", // Kopano-Konnect-Token
ScopesConf: bs.identifierScopesConf,
WebAppDisabled: bs.identifierWebAppDisabled,

AuthorizationEndpointURI: fullAuthorizationEndpointURL,

Expand Down
1 change: 1 addition & 0 deletions bootstrap/ldap.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func newLDAPIdentityManager(bs *bootstrap) (identity.Manager, error) {
StaticFolder: bs.identifierClientPath,
LogonCookieName: "__Secure-KKT", // Kopano-Konnect-Token
ScopesConf: bs.identifierScopesConf,
WebAppDisabled: bs.identifierWebAppDisabled,

AuthorizationEndpointURI: fullAuthorizationEndpointURL,

Expand Down
1 change: 1 addition & 0 deletions cmd/konnectd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func commandServe() *cobra.Command {
serveCmd.Flags().StringVar(&cfg.AuthorizationEndpointURI, "authorization-endpoint-uri", "", "Custom authorization endpoint URI")
serveCmd.Flags().StringVar(&cfg.EndsessionEndpointURI, "endsession-endpoint-uri", "", "Custom endsession endpoint URI")
serveCmd.Flags().StringVar(&cfg.IdentifierClientPath, "identifier-client-path", envOrDefault("KONNECTD_IDENTIFIER_CLIENT_PATH", defaultIdentifierClientPath), fmt.Sprintf("Path to the identifier web client base folder (default \"%s\")", defaultIdentifierClientPath))
serveCmd.Flags().BoolVar(&cfg.IdentifierWebAppDisabled, "disable-identifier-webapp", false, "Disable the identifier webapp if you want to use a different web-interface.")
serveCmd.Flags().StringVar(&cfg.IdentifierRegistrationConf, "identifier-registration-conf", "", "Path to a identifier-registration.yaml configuration file")
serveCmd.Flags().StringVar(&cfg.IdentifierScopesConf, "identifier-scopes-conf", "", "Path to a scopes.yaml configuration file")
serveCmd.Flags().BoolVar(&cfg.Insecure, "insecure", false, "Disable TLS certificate and hostname validation")
Expand Down
1 change: 1 addition & 0 deletions identifier/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type Config struct {
StaticFolder string
LogonCookieName string
ScopesConf string
WebAppDisabled bool

AuthorizationEndpointURI *url.URL

Expand Down
23 changes: 14 additions & 9 deletions identifier/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,24 @@ type Identifier struct {
// NewIdentifier returns a new Identifier.
func NewIdentifier(c *Config) (*Identifier, error) {
staticFolder := c.StaticFolder
webappIndexHTMLFilename := staticFolder + "/index.html"
if _, err := os.Stat(webappIndexHTMLFilename); os.IsNotExist(err) {
return nil, fmt.Errorf("identifier static client files: %v", err)
}
webappIndexHTML, err := ioutil.ReadFile(webappIndexHTMLFilename)
if err != nil {
return nil, fmt.Errorf("identifier failed to read client index.html: %v", err)
var webappIndexHTML = make([]byte, 0)

if !c.WebAppDisabled {
webappIndexHTMLFilename := staticFolder + "/index.html"
if _, err := os.Stat(webappIndexHTMLFilename); os.IsNotExist(err) {
return nil, fmt.Errorf("identifier static client files: %v", err)
}
webappIndexHTML, err := ioutil.ReadFile(webappIndexHTMLFilename)
if err != nil {
return nil, fmt.Errorf("identifier failed to read client index.html: %v", err)
}

webappIndexHTML = bytes.Replace(webappIndexHTML, []byte("__PATH_PREFIX__"), []byte(c.PathPrefix), 1)
}

oauth2CbEndpointURI, _ := url.Parse(c.BaseURI.String())
oauth2CbEndpointURI.Path = c.PathPrefix + "/identifier/oauth2/cb"

webappIndexHTML = bytes.Replace(webappIndexHTML, []byte("__PATH_PREFIX__"), []byte(c.PathPrefix), 1)

i := &Identifier{
Config: c,

Expand All @@ -118,6 +122,7 @@ func NewIdentifier(c *Config) (*Identifier, error) {
logger: c.Config.Logger,
}

var err error
i.meta = &meta.Meta{}
i.meta.Scopes, err = scopes.NewScopesFromFile(i.scopesConf, i.logger)
if err != nil {
Expand Down

0 comments on commit e7082c4

Please sign in to comment.