File tree Expand file tree Collapse file tree 4 files changed +13
-0
lines changed Expand file tree Collapse file tree 4 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,15 @@ public function performValidation($validateFullModel = false)
7878 $ messages ->appendMessage (new Message (gettext ('Illegal characters in token ' ), $ ref . '.authtype ' ));
7979 }
8080 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 ($ password ) > 512 ) {
85+ $ messages ->appendMessage (new Message (gettext ('Invalid value length ' ), $ ref . '.authtype ' ));
86+ } elseif (!preg_match ('/^[A-Za-z0-9-_.]+$/ ' , $ password )) {
87+ $ messages ->appendMessage (new Message (gettext ('Illegal characters in value ' ), $ ref . '.authtype ' ));
88+ }
89+ break ;
8190 }
8291 }
8392
Original file line number Diff line number Diff line change 7575 <OptionValues >
7676 <Basic >Basic</Basic >
7777 <Bearer >Bearer</Bearer >
78+ <Header >Header</Header >
7879 </OptionValues >
7980 </authtype >
8081 <categories type =" ModelRelationField" >
Original file line number Diff line number Diff line change 376376 $(" #alias\\ .password" ).show().attr(' placeholder' , ' {{lang._(' Password' )}}' );
377377 break ;
378378 case ' Bearer' :
379+ $(" #alias\\ .username" ).show().attr(' placeholder' , ' {{lang._(' HTTP Header' )}}' );
379380 $(" #alias\\ .password" ).show().attr(' placeholder' , ' {{lang._(' API token' )}}' );
380381 break ;
381382 }
Original file line number Diff line number Diff line change @@ -71,6 +71,8 @@ def iter_addresses(self, url):
7171 req_opts ['auth' ] = requests .auth .HTTPBasicAuth (self ._username , self ._password )
7272 elif self ._authtype == 'Bearer' :
7373 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
7476
7577 # fetch data
7678 try :
You can’t perform that action at this time.
0 commit comments