File tree Expand file tree Collapse file tree 4 files changed +20
-0
lines changed Expand file tree Collapse file tree 4 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,19 @@ public function performValidation($validateFullModel = false)
78
78
$ messages ->appendMessage (new Message (gettext ('Illegal characters in token ' ), $ ref . '.authtype ' ));
79
79
}
80
80
break ;
81
+ case 'Header ' :
82
+ if (empty ($ username ) || empty ($ password )) {
83
+ $ messages ->appendMessage (new Message (gettext ('Please provide a header key and value when Header auth is selected ' ), $ ref . '.authtype ' ));
84
+ } elseif (strlen ($ username ) > 255 ) {
85
+ $ messages ->appendMessage (new Message (gettext ('Invalid key length ' ), $ ref . '.authtype ' ));
86
+ } elseif (strlen ($ password ) > 512 ) {
87
+ $ messages ->appendMessage (new Message (gettext ('Invalid value length ' ), $ ref . '.authtype ' ));
88
+ } elseif (!preg_match ('/^[A-Za-z0-9-_.]+$/ ' , $ username )) {
89
+ $ messages ->appendMessage (new Message (gettext ('Illegal characters in key ' ), $ ref . '.authtype ' ));
90
+ } elseif (!preg_match ('/^[A-Za-z0-9-_.]+$/ ' , $ password )) {
91
+ $ messages ->appendMessage (new Message (gettext ('Illegal characters in value ' ), $ ref . '.authtype ' ));
92
+ }
93
+ break ;
81
94
}
82
95
}
83
96
Original file line number Diff line number Diff line change 75
75
<OptionValues >
76
76
<Basic >Basic</Basic >
77
77
<Bearer >Bearer</Bearer >
78
+ <Header >Header</Header >
78
79
</OptionValues >
79
80
</authtype >
80
81
<categories type =" ModelRelationField" >
Original file line number Diff line number Diff line change 378
378
case ' Bearer' :
379
379
$(" #alias\\ .password" ).show().attr(' placeholder' , ' {{lang._(' API token' )}}' );
380
380
break ;
381
+ case ' Header' :
382
+ $(" #alias\\ .username" ).show().attr(' placeholder' , ' {{lang._(' HTTP Header' )}}' );
383
+ $(" #alias\\ .password" ).show().attr(' placeholder' , ' {{lang._(' API token' )}}' );
384
+ break ;
381
385
}
382
386
});
383
387
$(" #alias\\ .authtype" ).change();
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ def iter_addresses(self, url):
71
71
req_opts ['auth' ] = requests .auth .HTTPBasicAuth (self ._username , self ._password )
72
72
elif self ._authtype == 'Bearer' :
73
73
req_opts ['headers' ]['Authorization' ] = f'Bearer { self ._password } '
74
+ elif self ._authtype == 'Header' and self ._username is not None :
75
+ req_opts ['headers' ][self ._username ] = self ._password
74
76
75
77
# fetch data
76
78
try :
You can’t perform that action at this time.
0 commit comments