Using swagger/swashbuckle .net core operation filters to enable API testing

The problem arises in solutions which contains identity servers based on OAuth2 and OpenId protocols (For example Identity Server, WSO2 identity cloud, etc) and Rest API with swagger swashbuckle used for auto documenting and testing. Each API call should contain authentication token otherwise testing API ("Try it out") will not work.

The problem arises in solutions which contains identity servers based on OAuth2 and OpenId protocols (For example Identity Server, WSO2 identity cloud, etc) and Rest API with swagger swashbuckle used for auto documenting and testing. Each API call should contain authentication token otherwise testing API (“Try it out”) will not work.

Solution

One of the option to enable API testing (“Try it out” button) is using swagger operation filter. In example below was created operation filter which includes Bearer authentication token field to HTTP header of each API calls..

Complete article can be found here

Examples can be found here