Fix nil pointer exception in webfinger
Co-authoredjby: Jörn Dreyer <jdreyer@owncloud.com> Signed-off-by: Christian Richter <crichter@owncloud.com>
This commit is contained in:
@@ -39,7 +39,7 @@ func OidcAuth(opts ...Option) func(http.Handler) http.Handler {
|
|||||||
// it will fetch the keys from the issuer using the .well-known
|
// it will fetch the keys from the issuer using the .well-known
|
||||||
// endpoint
|
// endpoint
|
||||||
return goidc.NewProvider(
|
return goidc.NewProvider(
|
||||||
context.WithValue(context.Background(), oauth2.HTTPClient, http.Client{}),
|
context.WithValue(context.Background(), oauth2.HTTPClient, &opt.HttpClient),
|
||||||
opt.OidcIssuer,
|
opt.OidcIssuer,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ func OidcAuth(opts ...Option) func(http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userInfo, err := provider.UserInfo(
|
userInfo, err := provider.UserInfo(
|
||||||
context.WithValue(ctx, oauth2.HTTPClient, http.Client{}),
|
context.WithValue(ctx, oauth2.HTTPClient, &opt.HttpClient),
|
||||||
oauth2.StaticTokenSource(oauth2Token),
|
oauth2.StaticTokenSource(oauth2Token),
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
gatewayv1beta1 "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||||
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
"github.com/owncloud/ocis/v2/ocis-pkg/log"
|
||||||
)
|
)
|
||||||
@@ -16,6 +18,8 @@ type Options struct {
|
|||||||
OidcIssuer string
|
OidcIssuer string
|
||||||
// GatewayAPIClient is a reva gateway client
|
// GatewayAPIClient is a reva gateway client
|
||||||
GatewayAPIClient gatewayv1beta1.GatewayAPIClient
|
GatewayAPIClient gatewayv1beta1.GatewayAPIClient
|
||||||
|
// HttpClient is a http client
|
||||||
|
HttpClient http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithLogger provides a function to set the openid connect issuer option.
|
// WithLogger provides a function to set the openid connect issuer option.
|
||||||
@@ -38,3 +42,10 @@ func WithGatewayAPIClient(val gatewayv1beta1.GatewayAPIClient) Option {
|
|||||||
o.GatewayAPIClient = val
|
o.GatewayAPIClient = val
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HttpClient provides a function to set the http client option.
|
||||||
|
func WithHttpClient(val http.Client) Option {
|
||||||
|
return func(o *Options) {
|
||||||
|
o.HttpClient = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ type Config struct {
|
|||||||
Relations []string `yaml:"relations" env:"WEBFINGER_RELATIONS" desc:"A comma-separated list of relation URIs or registered relation types to add to webfinger responses."`
|
Relations []string `yaml:"relations" env:"WEBFINGER_RELATIONS" desc:"A comma-separated list of relation URIs or registered relation types to add to webfinger responses."`
|
||||||
IDP string `yaml:"idp" env:"OCIS_URL;OCIS_OIDC_ISSUER;WEBFINGER_OIDC_ISSUER" desc:"The identity provider href for the openid-discovery relation."`
|
IDP string `yaml:"idp" env:"OCIS_URL;OCIS_OIDC_ISSUER;WEBFINGER_OIDC_ISSUER" desc:"The identity provider href for the openid-discovery relation."`
|
||||||
OcisURL string `yaml:"ocis_url" env:"OCIS_URL;WEBFINGER_OWNCLOUD_SERVER_INSTANCE_URL" desc:"The URL for the legacy ownCloud server instance relation (not to be confused with the product ownCloud Server). It defaults to the OCIS_URL but can be overridden to support some reverse proxy corner cases. To shard the deployment, multiple instances can be configured in the configuration file."`
|
OcisURL string `yaml:"ocis_url" env:"OCIS_URL;WEBFINGER_OWNCLOUD_SERVER_INSTANCE_URL" desc:"The URL for the legacy ownCloud server instance relation (not to be confused with the product ownCloud Server). It defaults to the OCIS_URL but can be overridden to support some reverse proxy corner cases. To shard the deployment, multiple instances can be configured in the configuration file."`
|
||||||
|
Insecure bool `yaml:"insecure" env:"OCIS_INSECURE;WEBFINGER_INSECURE" desc:"Allow insecure connections to the WEBFINGER service."`
|
||||||
|
|
||||||
Context context.Context `yaml:"-"`
|
Context context.Context `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ func DefaultConfig() *config.Config {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
IDP: "https://localhost:9200",
|
||||||
|
Insecure: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package http
|
package http
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"github.com/go-chi/chi/v5"
|
||||||
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
chimiddleware "github.com/go-chi/chi/v5/middleware"
|
||||||
@@ -60,9 +62,21 @@ func Server(opts ...Option) (ohttp.Service, error) {
|
|||||||
version.String,
|
version.String,
|
||||||
))
|
))
|
||||||
|
|
||||||
|
var oidcHTTPClient = &http.Client{
|
||||||
|
Transport: &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
InsecureSkipVerify: options.Config.Insecure, //nolint:gosec
|
||||||
|
},
|
||||||
|
DisableKeepAlives: true,
|
||||||
|
},
|
||||||
|
Timeout: time.Second * 10,
|
||||||
|
}
|
||||||
|
|
||||||
mux.Use(middleware.OidcAuth(
|
mux.Use(middleware.OidcAuth(
|
||||||
middleware.WithLogger(options.Logger),
|
middleware.WithLogger(options.Logger),
|
||||||
middleware.WithOidcIssuer(options.Config.IDP),
|
middleware.WithOidcIssuer(options.Config.IDP),
|
||||||
|
middleware.WithHttpClient(*oidcHTTPClient),
|
||||||
))
|
))
|
||||||
|
|
||||||
// this logs http request related data
|
// this logs http request related data
|
||||||
|
|||||||
Reference in New Issue
Block a user