@@ -106,6 +106,62 @@ public function withAuthenticationToken(string $domain, string $auth): self
106106 return $ this ;
107107 }
108108
109+ public function withGitlabOauthAuthentication (string $ token , string $ domain = 'gitlab.com ' ): self
110+ {
111+ $ this ->authenticationTokens [$ domain ] = [
112+ 'type ' => 'gitlab-oauth ' ,
113+ 'url ' => $ domain ,
114+ 'token ' => $ token ,
115+ ];
116+
117+ return $ this ;
118+ }
119+
120+ public function withGitlabTokenAuthentication (string $ token , string $ domain = 'gitlab.com ' ): self
121+ {
122+ $ this ->authenticationTokens [$ domain ] = [
123+ 'type ' => 'gitlab-token ' ,
124+ 'url ' => $ domain ,
125+ 'token ' => $ token ,
126+ ];
127+
128+ return $ this ;
129+ }
130+
131+ public function withGithubOauthAuthentication (string $ token , string $ domain = 'github.com ' ): self
132+ {
133+ $ this ->authenticationTokens [$ domain ] = [
134+ 'type ' => 'github-oauth ' ,
135+ 'url ' => $ domain ,
136+ 'token ' => $ token ,
137+ ];
138+
139+ return $ this ;
140+ }
141+
142+ public function withHttpBasicAuthentication (string $ domain , string $ username , string $ password ): self
143+ {
144+ $ this ->authenticationTokens [$ domain ] = [
145+ 'type ' => 'http-basic ' ,
146+ 'url ' => $ domain ,
147+ 'username ' => $ username ,
148+ 'password ' => $ password ,
149+ ];
150+
151+ return $ this ;
152+ }
153+
154+ public function withHttpBearerAuthentication (string $ domain , string $ token ): self
155+ {
156+ $ this ->authenticationTokens [$ domain ] = [
157+ 'type ' => 'http-basic ' ,
158+ 'url ' => $ domain ,
159+ 'token ' => $ token ,
160+ ];
161+
162+ return $ this ;
163+ }
164+
109165 public function build (): Configurator \SatelliteInterface
110166 {
111167 if (!file_exists ($ this ->workdir )) {
@@ -153,8 +209,15 @@ public function build(): Configurator\SatelliteInterface
153209 }
154210
155211 if (\count ($ this ->authenticationTokens ) > 0 ) {
156- foreach ($ this ->authenticationTokens as $ url => $ token ) {
157- $ composer ->addAuthenticationToken ($ url , $ token );
212+ foreach ($ this ->authenticationTokens as $ url => $ authentication ) {
213+ match ($ authentication ['type ' ]) {
214+ 'gitlab-oauth ' => $ composer ->addGitlabOauthAuthentication ($ authentication ['token ' ]),
215+ 'gitlab-token ' => $ composer ->addGitlabTokenAuthentication ($ authentication ['token ' ]),
216+ 'github-oauth ' => $ composer ->addGithubOauthAuthentication ($ authentication ['token ' ]),
217+ 'http-basic ' => $ composer ->addHttpBasicAuthentication ($ url , $ authentication ['username ' ], $ authentication ['password ' ]),
218+ 'http-bearer ' => $ composer ->addHttpBearerAuthentication ($ url , $ authentication ['token ' ]),
219+ default => $ composer ->addAuthenticationToken ($ url , $ authentication ['token ' ]),
220+ };
158221 }
159222 }
160223
0 commit comments