@@ -35,6 +35,7 @@ import (
3535
3636type wayfHandler struct {
3737 federations []Federation
38+ ocmClient * ocmd.OCMClient
3839}
3940
4041type Federation struct {
@@ -71,6 +72,13 @@ type DiscoverResponse struct {
7172func (h * wayfHandler ) init (c * config ) error {
7273 log := appctx .GetLogger (context .Background ())
7374
75+ // Create OCM client for discovery from config
76+ h .ocmClient = ocmd .NewClient (time .Duration (c .OCMClientTimeout )* time .Second , c .OCMClientInsecure )
77+ log .Debug ().
78+ Int ("timeout_seconds" , c .OCMClientTimeout ).
79+ Bool ("insecure" , c .OCMClientInsecure ).
80+ Msg ("Created OCM client for discovery" )
81+
7482 log .Debug ().Str ("file" , c .FederationsFile ).Msg ("Initializing WAYF handler with federations file" )
7583
7684 data , err := os .ReadFile (c .FederationsFile )
@@ -92,10 +100,6 @@ func (h *wayfHandler) init(c *config) error {
92100
93101 log .Debug ().Int ("federations_count" , len (fileData )).Msg ("Loaded federations from file" )
94102
95- // Create OCM client for discovery
96- ocmClient := ocmd .NewClient (10 * time .Second , false )
97- log .Debug ().Msg ("Created OCM client for discovery" )
98-
99103 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Minute )
100104 defer cancel ()
101105
@@ -120,7 +124,7 @@ func (h *wayfHandler) init(c *config) error {
120124 log .Debug ().Str ("federation" , fed .Federation ).Str ("server" , srv .DisplayName ).Str ("url" , srv .URL ).Msg ("Discovering server" )
121125
122126 // Discover inviteAcceptDialog from OCM endpoint
123- disco , err := ocmClient .Discover (ctx , srv .URL )
127+ disco , err := h . ocmClient .Discover (ctx , srv .URL )
124128 if err != nil {
125129 log .Warn ().Err (err ).
126130 Str ("federation" , fed .Federation ).
@@ -219,11 +223,8 @@ func (h *wayfHandler) DiscoverProvider(w http.ResponseWriter, r *http.Request) {
219223 return
220224 }
221225
222- // Create OCM client with timeout
223- ocmClient := ocmd .NewClient (10 * time .Second , false )
224-
225226 log .Debug ().Str ("domain" , domain ).Msg ("Attempting OCM discovery" )
226- disco , err := ocmClient .Discover (ctx , domain )
227+ disco , err := h . ocmClient .Discover (ctx , domain )
227228 if err != nil {
228229 log .Warn ().Err (err ).Str ("domain" , domain ).Msg ("Discovery failed" )
229230 reqres .WriteError (w , r , reqres .APIErrorNotFound ,
0 commit comments