WSO2 Microgateway oauth2 optional when custom header is present

115 views Asked by At

I have a scenario to implement when there are two authentication options one is Oauth2 and another one is custom header "x-api-key". I want to pass the request to the backend without authorization if only the x-api-key is present. Can this be achieved using a custom filter?

1

There are 1 answers

1
chashikajw On

Currently, we don't have any option for this. But you can give a try to write a custom filter including the below code and place it before the Auth filter.

  string X_API_HEADER_NAME = "x-api-key";
  string SKIP_ALL_FILTERS = "skip_filters";

  if (request.hasHeader(X_API_HEADER_NAME)) {
        context.attributes[SKIP_ALL_FILTERS] = true;
    }