Browse Source

Fix retry authentification on gitlab oauth

Jerome TAMARELLE 9 years ago
parent
commit
db056b8383
2 changed files with 11 additions and 23 deletions
  1. 1 1
      src/Composer/Repository/Vcs/GitLabDriver.php
  2. 10 22
      src/Composer/Util/GitLab.php

+ 1 - 1
src/Composer/Repository/Vcs/GitLabDriver.php

@@ -286,7 +286,7 @@ class GitLabDriver extends VcsDriver
             $this->remoteFilesystem
         );
         $this->gitDriver->initialize();
-    }    
+    }
 
     /**
      * {@inheritDoc}

+ 10 - 22
src/Composer/Util/GitLab.php

@@ -51,7 +51,7 @@ class GitLab
      */
     public function authorizeOAuth($originUrl)
     {
-        if (!in_array($originUrl, $this->config->get('gitlab-domains'))) {
+        if (!in_array($originUrl, $this->config->get('gitlab-domains'), true)) {
             return false;
         }
 
@@ -122,37 +122,25 @@ class GitLab
 
     private function createToken($originUrl)
     {
-        if (!$this->io->hasAuthentication($originUrl)) {
-            $username = $this->io->ask('Username: ');
-            $password = $this->io->askAndHideAnswer('Password: ');
-
-            $this->io->setAuthentication($originUrl, $username, $password);
-        }
-
+        $username = $this->io->ask('Username: ');
+        $password = $this->io->askAndHideAnswer('Password: ');
 
         $headers = array('Content-Type: application/x-www-form-urlencoded');
 
-        $note = 'Composer';
-        if ($this->config->get('GitLab-expose-hostname') === true && 0 === $this->process->execute('hostname', $output)) {
-            $note .= ' on ' . trim($output);
-        }
-        $note .= ' [' . date('YmdHis') . ']';
-
         $apiUrl = $originUrl ;
-        $data = http_build_query(
-            array(
-                'username'  => $username,
-                'password'  => $password,
-                'grant_type' => 'password',
-                )
-            );
+        $data = http_build_query(array(
+            'username'  => $username,
+            'password'  => $password,
+            'grant_type' => 'password',
+        ));
         $options = array(
             'retry-auth-failure' => false,
             'http' => array(
                 'method' => 'POST',
                 'header' => $headers,
                 'content' => $data
-            ));
+            ),
+        );
 
         $json = $this->remoteFilesystem->getContents($originUrl, 'http://'. $apiUrl . '/oauth/token', false, $options);