@@ -195,9 +195,13 @@ protected function execute(InputInterface $input, OutputInterface $output) {
195195
196196 $ identifier = $ input ->getArgument ('identifier ' );
197197 $ clientId = $ input ->getOption ('clientid ' );
198+ $ clientSecret = $ input ->getOption ('clientsecret ' );
199+ $ clientSecretFile = $ input ->getOption ('clientsecret-file ' );
200+ $ clientSecretEnv = $ input ->getOption ('clientsecret-env ' );
198201 try {
199- $ clientSecret = $ this ->getClientSecretInput ($ input , $ output );
202+ $ clientSecret = $ this ->getClientSecretInput ($ clientSecret , $ clientSecretFile , $ clientSecretEnv , $ output );
200203 } catch (\Exception $ e ) {
204+ $ output ->writeln ($ e ->getMessage ());
201205 return 1 ;
202206 }
203207 $ discoveryuri = $ input ->getOption ('discoveryuri ' );
@@ -310,44 +314,39 @@ private function listProviders(InputInterface $input, OutputInterface $output) {
310314 return 0 ;
311315 }
312316
313- private function getClientSecretInput (InputInterface $ input , OutputInterface $ output ): ?string {
314- $ clientSecret = $ input ->getOption ('clientsecret ' );
315- $ clientSecretFile = $ input ->getOption ('clientsecret-file ' );
316- $ clientSecretEnv = $ input ->getOption ('clientsecret-env ' );
317+ private function getClientSecretInput (
318+ ?string $ clientSecret , ?string $ clientSecretFile , ?string $ clientSecretEnv , OutputInterface $ output ,
319+ ): ?string {
317320 if (
318321 ($ clientSecret !== null && $ clientSecretFile !== null )
319322 || ($ clientSecret !== null && $ clientSecretEnv !== null )
320323 || ($ clientSecretFile !== null && $ clientSecretEnv !== null )
321324 ) {
322- $ output ->writeln ('<comment>Only one of "--clientsecret", "--clientsecret-file" or "--clientsecret-env" can be used.</comment> ' );
323- throw new \Exception ();
325+ throw new \Exception ('<comment>Only one of "--clientsecret", "--clientsecret-file" or "--clientsecret-env" can be used.</comment> ' );
324326 }
325327 if ($ clientSecret !== null ) {
326- $ clientSecret = $ this ->crypto ->encrypt ($ clientSecret );
328+ return $ this ->crypto ->encrypt ($ clientSecret );
327329 }
328- if ($ clientSecretFile ) {
330+ if ($ clientSecretFile !== null ) {
329331 $ clientSecret = file_get_contents ($ clientSecretFile );
330332 if (is_string ($ clientSecret ) && $ clientSecret !== '' ) {
331- $ clientSecret = trim ($ clientSecret );
332- $ clientSecret = $ this ->crypto ->encrypt ($ clientSecret );
333333 $ output ->writeln ('<info>Client secret loaded from file " ' . $ clientSecretFile . '"</info> ' );
334+ $ clientSecret = trim ($ clientSecret );
335+ return $ this ->crypto ->encrypt ($ clientSecret );
334336 } else {
335- $ output ->writeln ('<error>Client secret file " ' . $ clientSecretFile . '" could not be read or is empty</error> ' );
336- throw new \Exception ();
337+ throw new \Exception ('<error>Client secret file " ' . $ clientSecretFile . '" could not be read or is empty</error> ' );
337338 }
338339 }
339- if ($ clientSecretEnv ) {
340+ if ($ clientSecretEnv !== null ) {
340341 $ clientSecret = getenv ($ clientSecretEnv );
341342 if (is_string ($ clientSecret ) && $ clientSecret !== '' ) {
342- $ clientSecret = trim ($ clientSecret );
343- $ clientSecret = $ this ->crypto ->encrypt ($ clientSecret );
344343 $ output ->writeln ('<info>Client secret loaded from environment variable " ' . $ clientSecretEnv . '"</info> ' );
344+ $ clientSecret = trim ($ clientSecret );
345+ return $ this ->crypto ->encrypt ($ clientSecret );
345346 } else {
346- $ output ->writeln ('<error>Client secret environment variable " ' . $ clientSecretFile . '" could not be read or is empty</error> ' );
347- throw new \Exception ();
347+ throw new \Exception ('<error>Client secret environment variable " ' . $ clientSecretEnv . '" could not be read or is empty</error> ' );
348348 }
349349 }
350-
351- return $ clientSecret ;
350+ return null ;
352351 }
353352}
0 commit comments