File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,13 @@ export async function hook(
39
39
parameters
40
40
) as EndpointDefaults & { url : string } ;
41
41
42
+ // Do not intercept OAuth Web/Device flow request
43
+ if (
44
+ / \/ l o g i n \/ ( o a u t h \/ a c c e s s _ t o k e n | d e v i c e \/ c o d e ) $ / . test ( endpoint . url as string )
45
+ ) {
46
+ return request ( endpoint ) ;
47
+ }
48
+
42
49
if ( requiresBasicAuth ( endpoint . url ) ) {
43
50
const credentials = btoa ( `${ state . clientId } :${ state . clientSecret } ` ) ;
44
51
endpoint . headers . authorization = `basic ${ credentials } ` ;
Original file line number Diff line number Diff line change @@ -164,3 +164,42 @@ test("Sets clientId/clientSecret as Basic auth for /authentication/{clientId}/*
164
164
165
165
expect ( data ) . toEqual ( { ok : true } ) ;
166
166
} ) ;
167
+
168
+ test ( "Sets no auth auth for OAuth Web flow requests" , async ( ) => {
169
+ const matchCreateTokenRequest : MockMatcherFunction = ( url , options ) => {
170
+ expect ( url ) . toEqual ( "https://github.com/login/oauth/access_token" ) ;
171
+ // @ts -ignore
172
+ expect ( options . headers . authorization ) . toBeUndefined ( ) ;
173
+
174
+ return true ;
175
+ } ;
176
+
177
+ const mock = fetchMock
178
+ . sandbox ( )
179
+ . postOnce ( matchCreateTokenRequest , { ok : true } ) ;
180
+
181
+ const octokit = new Octokit ( {
182
+ authStrategy : createOAuthUserAuth ,
183
+ auth : {
184
+ clientId : "1234567890abcdef1234" ,
185
+ clientSecret : "1234567890abcdef1234567890abcdef12345678" ,
186
+ code : "code123" ,
187
+ } ,
188
+ request : {
189
+ fetch : mock ,
190
+ } ,
191
+ } ) ;
192
+
193
+ // Exchanges the code for the user access token authentication on first request
194
+ // and caches the authentication for successive requests
195
+ const { data } = await octokit . request (
196
+ "POST https://github.com/login/oauth/access_token" ,
197
+ {
198
+ client_id : "1234567890abcdef1234" ,
199
+ client_secret : "client_secret" ,
200
+ code : "code123" ,
201
+ }
202
+ ) ;
203
+
204
+ expect ( data ) . toEqual ( { ok : true } ) ;
205
+ } ) ;
You can’t perform that action at this time.
0 commit comments