Certificate based authentication on the microgateway is authenticating a request based on a digital certificate, before granting access to the backend. By way of certificate based authentication the microgateway supports mutual SSL. In mutual SSL, both parties the client and the server identifies themselves in order to create a successful SSL connection. Mutual SSL allows a client to make a request without a username and password, provided that the server is aware of the client's certificate.
Enabling Certificate Based Authentication on WSO2 Microgateway
This tutorial wil be using a microgateway distribution for a single API that is in the Published state. For details on how to create a Microgateway distribution for a group of APIs, see Importing APIs Using Microgateway Labels.
Lets create a microgateway project/
- Navigate to a preferred workspace folder using the command line. (This location is used to run the Microgateway commands and to generate Microgateway artifacts.)
- Create a project using the command given below
Now lets add the API(open API definition) to the project. Navigate to the
/petstore/api_definitionsdirectory. Add the API definition(s) to th
isdirectory. A sample open API definition can be found here.
Build the microgateway distribution for the project using the following command:
Once the above command is executed, An executable file (
/petstore/target/petstore.balx) is created to expose the API via WSO2 API Microgateway
- Navigate to the
<MGW-Toolkit-HOME>/resources/conf folder and open the “micro-gw.conf" file.
- Locate the "sslVerifyClient" property and change the value to "required". This will enable mutual SSL.
Configure the truststore.Change “trustStore.path” property and “trustStore.password” property under “[listenerConfig]” instance ID. The trustore should have the certificate which is used to create SSL connections.
In this tutorial, a self signed certificate is added into the already available ballerina truststore.
Now lets run the micro gateway dokcer runtime mouting executabel file(petstore.balx) and the config file (micro-gw.conf).
Invoking an API using certificate based authentication
When invoking an API, you can pass the certificate to the API Microgateway as follows.
The instructions below are based on Firefox 65.0.1.
- Navigate to the browsers certificate management section. on Firefox, navigate to Preferences > Privacy & Security > Certificates
- Add the certificate used for the SSL connection.
- Invoke the REST API using a REST API client from the browser.
- The browser will present a user identification request, to select a certificate in order to use for the SSL connection. Select the certificate you added and click OK.