@@ -9,7 +9,7 @@ use crate::formatter;
99use crate :: util;
1010
1111pub async fn list ( cfg : & Config ) -> Result < ( ) > {
12- let api = crate :: make_api_no_auth !( AuthNMappingsAPI , cfg) ;
12+ let api = crate :: make_api !( AuthNMappingsAPI , cfg) ;
1313 let resp = api
1414 . list_authn_mappings ( ListAuthNMappingsOptionalParams :: default ( ) )
1515 . await
@@ -18,7 +18,7 @@ pub async fn list(cfg: &Config) -> Result<()> {
1818}
1919
2020pub async fn get ( cfg : & Config , mapping_id : & str ) -> Result < ( ) > {
21- let api = crate :: make_api_no_auth !( AuthNMappingsAPI , cfg) ;
21+ let api = crate :: make_api !( AuthNMappingsAPI , cfg) ;
2222 let resp = api
2323 . get_authn_mapping ( mapping_id. to_string ( ) )
2424 . await
@@ -28,7 +28,7 @@ pub async fn get(cfg: &Config, mapping_id: &str) -> Result<()> {
2828
2929pub async fn create ( cfg : & Config , file : & str ) -> Result < ( ) > {
3030 let body: AuthNMappingCreateRequest = util:: read_json_file ( file) ?;
31- let api = crate :: make_api_no_auth !( AuthNMappingsAPI , cfg) ;
31+ let api = crate :: make_api !( AuthNMappingsAPI , cfg) ;
3232 let resp = api
3333 . create_authn_mapping ( body)
3434 . await
@@ -38,7 +38,7 @@ pub async fn create(cfg: &Config, file: &str) -> Result<()> {
3838
3939pub async fn update ( cfg : & Config , mapping_id : & str , file : & str ) -> Result < ( ) > {
4040 let body: AuthNMappingUpdateRequest = util:: read_json_file ( file) ?;
41- let api = crate :: make_api_no_auth !( AuthNMappingsAPI , cfg) ;
41+ let api = crate :: make_api !( AuthNMappingsAPI , cfg) ;
4242 let resp = api
4343 . update_authn_mapping ( mapping_id. to_string ( ) , body)
4444 . await
@@ -47,7 +47,7 @@ pub async fn update(cfg: &Config, mapping_id: &str, file: &str) -> Result<()> {
4747}
4848
4949pub async fn delete ( cfg : & Config , mapping_id : & str ) -> Result < ( ) > {
50- let api = crate :: make_api_no_auth !( AuthNMappingsAPI , cfg) ;
50+ let api = crate :: make_api !( AuthNMappingsAPI , cfg) ;
5151 api. delete_authn_mapping ( mapping_id. to_string ( ) )
5252 . await
5353 . map_err ( |e| anyhow:: anyhow!( "failed to delete AuthN mapping: {e:?}" ) ) ?;
@@ -115,6 +115,38 @@ mod tests {
115115 std:: env:: remove_var ( "DD_TOKEN_STORAGE" ) ;
116116 }
117117
118+ #[ tokio:: test]
119+ async fn test_authn_mappings_list_accepts_oauth_bearer_token ( ) {
120+ let _lock = lock_env ( ) . await ;
121+ std:: env:: set_var ( "DD_TOKEN_STORAGE" , "file" ) ;
122+ let mut server = mockito:: Server :: new_async ( ) . await ;
123+ let mut cfg = test_config ( & server. url ( ) ) ;
124+ // Simulate OAuth-only auth: bearer token configured, no API/APP keys.
125+ cfg. api_key = None ;
126+ cfg. app_key = None ;
127+ cfg. access_token = Some ( "oauth-bearer-token" . into ( ) ) ;
128+ std:: env:: remove_var ( "DD_API_KEY" ) ;
129+ std:: env:: remove_var ( "DD_APP_KEY" ) ;
130+
131+ let _mock = server
132+ . mock ( "GET" , mockito:: Matcher :: Any )
133+ . match_header ( "Authorization" , "Bearer oauth-bearer-token" )
134+ . with_status ( 200 )
135+ . with_header ( "content-type" , "application/json" )
136+ . with_body ( r#"{"data":[]}"# )
137+ . create_async ( )
138+ . await ;
139+
140+ let result = super :: list ( & cfg) . await ;
141+ assert ! (
142+ result. is_ok( ) ,
143+ "authn mappings list with OAuth bearer failed: {:?}" ,
144+ result. err( )
145+ ) ;
146+ cleanup_env ( ) ;
147+ std:: env:: remove_var ( "DD_TOKEN_STORAGE" ) ;
148+ }
149+
118150 #[ tokio:: test]
119151 async fn test_authn_mappings_list_error ( ) {
120152 let _lock = lock_env ( ) . await ;
0 commit comments