File tree 2 files changed +33
-9
lines changed
2 files changed +33
-9
lines changed Original file line number Diff line number Diff line change @@ -189,6 +189,30 @@ describe('util/http/auth', () => {
189
189
token : 'test' ,
190
190
} ) ;
191
191
} ) ;
192
+
193
+ it ( `honors authType` , ( ) => {
194
+ const opts : GotOptions = {
195
+ headers : { } ,
196
+ token : 'test' ,
197
+ context : {
198
+ authType : 'Bearer' ,
199
+ } ,
200
+ hostType : 'custom' ,
201
+ } ;
202
+
203
+ applyAuthorization ( opts ) ;
204
+
205
+ expect ( opts ) . toEqual ( {
206
+ context : {
207
+ authType : 'Bearer' ,
208
+ } ,
209
+ headers : {
210
+ authorization : 'Bearer test' ,
211
+ } ,
212
+ hostType : 'custom' ,
213
+ token : 'test' ,
214
+ } ) ;
215
+ } ) ;
192
216
} ) ;
193
217
194
218
describe ( 'removeAuthorization' , ( ) => {
Original file line number Diff line number Diff line change @@ -29,7 +29,14 @@ export function applyAuthorization<GotOptions extends AuthGotOptions>(
29
29
30
30
options . headers ??= { } ;
31
31
if ( options . token ) {
32
- if (
32
+ const authType = options . context ?. authType ;
33
+ if ( authType ) {
34
+ if ( authType === 'Token-Only' ) {
35
+ options . headers . authorization = options . token ;
36
+ } else {
37
+ options . headers . authorization = `${ authType } ${ options . token } ` ;
38
+ }
39
+ } else if (
33
40
options . hostType &&
34
41
GITEA_API_USING_HOST_TYPES . includes ( options . hostType )
35
42
) {
@@ -61,14 +68,7 @@ export function applyAuthorization<GotOptions extends AuthGotOptions>(
61
68
options . headers . authorization = `Bearer ${ options . token } ` ;
62
69
}
63
70
} else {
64
- // Custom Auth type, eg `Basic XXXX_TOKEN`
65
- const type = options . context ?. authType ?? 'Bearer' ;
66
-
67
- if ( type === 'Token-Only' ) {
68
- options . headers . authorization = options . token ;
69
- } else {
70
- options . headers . authorization = `${ type } ${ options . token } ` ;
71
- }
71
+ options . headers . authorization = `Bearer ${ options . token } ` ;
72
72
}
73
73
delete options . token ;
74
74
} else if ( options . password !== undefined ) {
You can’t perform that action at this time.
0 commit comments