@@ -79,12 +79,7 @@ private static function registerWorkflowWebhooks($workflow, $basePath)
7979 if ($ method ->getName () === 'execute ' ) {
8080 $ slug = Str::kebab (class_basename ($ workflow ));
8181 Route::post ("{$ basePath }/start/ {$ slug }" , static function (Request $ request ) use ($ workflow ) {
82- if (! self ::validateAuth ($ request )) {
83- return response ()->json ([
84- 'error ' => 'Unauthorized ' ,
85- ], 401 );
86- }
87-
82+ $ request = self ::validateAuth ($ request );
8883 $ params = self ::resolveNamedParameters ($ workflow , 'execute ' , $ request ->all ());
8984 WorkflowStub::make ($ workflow )->start (...$ params );
9085 return response ()->json ([
@@ -101,24 +96,17 @@ private static function registerSignalWebhooks($workflow, $basePath)
10196 if (self ::hasWebhookAttributeOnMethod ($ method )) {
10297 $ slug = Str::kebab (class_basename ($ workflow ));
10398 $ signal = Str::kebab ($ method ->getName ());
104-
10599 Route::post (
106100 "{$ basePath }/signal/ {$ slug }/{workflowId}/ {$ signal }" ,
107101 static function (Request $ request , $ workflowId ) use ($ workflow , $ method ) {
108- if (! self ::validateAuth ($ request )) {
109- return response ()->json ([
110- 'error ' => 'Unauthorized ' ,
111- ], 401 );
112- }
113-
102+ $ request = self ::validateAuth ($ request );
114103 $ workflowInstance = WorkflowStub::load ($ workflowId );
115104 $ params = self ::resolveNamedParameters (
116105 $ workflow ,
117106 $ method ->getName (),
118107 $ request ->except ('workflow_id ' )
119108 );
120109 $ workflowInstance ->{$ method ->getName ()}(...$ params );
121-
122110 return response ()->json ([
123111 'message ' => 'Signal sent ' ,
124112 ]);
@@ -164,7 +152,7 @@ private static function resolveNamedParameters($class, $method, $payload)
164152 return $ params ;
165153 }
166154
167- private static function validateAuth (Request $ request ): bool
155+ private static function validateAuth (Request $ request ): Request
168156 {
169157 $ authenticatorClass = match (config ('workflows.webhook_auth.method ' , 'none ' )) {
170158 'none ' => NullAuthenticator::class,
@@ -174,10 +162,10 @@ private static function validateAuth(Request $request): bool
174162 default => null ,
175163 };
176164
177- if (is_subclass_of ($ authenticatorClass , WebhookAuthenticator::class)) {
178- return ( new $ authenticatorClass ())-> validate ( $ request );
165+ if (! is_subclass_of ($ authenticatorClass , WebhookAuthenticator::class)) {
166+ abort ( 401 , ' Unauthorized ' );
179167 }
180168
181- return false ;
169+ return ( new $ authenticatorClass ())-> validate ( $ request ) ;
182170 }
183171}
0 commit comments