Skip to main content

An example of authentication at gateway while proxied API calls are "trusted"

API Cloud provides the authorization of the APIs published using basic auth. But what do we do if our back-end is also secured using a different mechanism. In this blog i will explain how we can create and API and invoke a back-end when the back-end has been secured using a user name and password.


To demonstrate this sample i will be using a JAX-RS based service used in the WSO2 APP cloud. It is a basic jax-rs application very much like the one found here. It is a service that can be used to get the id and name of a customer when the id is passed as a parameter which is the operation I will be using to demonstrate the example. This service cannot be accessed unless we provide the credentials.

The service was secured in the manner explained in this blog. A security constraint tag was included to the web.xml of the jax-rs service which will require credentials if we need to invoke the methods of this service using our API.

First Let’s create our API to demonstrate the scenario.

1. Log in to WSO2 Cloud and navigate to the API Cloud where it will direct you to the publisher portal. If you do not have an account you can find the steps here.

2. Create a new API and use the guidelines in the image below to design the API. Give the request URI as customerservice/customers/{id} and select implement.



3. In the implement tab we need to give the endpoint as https://appserver.dev.cloud.wso2.com/t/backstage/webapps/customerdetailservi-default-SNAPSHOT/services/customers/customerservice and select the Endpoint Security Scheme as ‘Secured’ under ‘Show more options’.


4. Here we need to provide the credential we have used to secure our back-end service.




5. After which the tiers were selected and the API was published in the store.


6. After the API has been successfully created we can invoking after subscribing to the API using an application and observe the result.


7. Provide the value 123 for the id and Try it. You will see a response as below.




8. Let’s remove the secured property and try to invoke the API again.


9. Go to the API Publisher and select edit option for the API created above.

10. In the implement tab click the ‘Show more options’ link and change the endpoint security scheme as ‘Non Secured’.

11. Save and Publish the API again.

12. Go back to the API Store and invoke the GET method using the id value as 123. You will be unauthorized since the back-end cannot be access unless we pass the required authorization.
   

References:

[1] http://wso2.com/blogs/cloud/your-own-jax-rs-as-an-oauth-web-api-in-minutes/

[2] https://appserver.dev.cloud.wso2.com/t/backstage/webapps/customerdetailservi-default-SNAPSHOT/services/
[3] https://docs.wso2.com/display/AS530/JAX-RS+Basics
[4] http://shenavid.blogspot.com/2015/10/wso2-cloud-wso2-cloud-consists-of-two.html
[5] https://docs.wso2.com/display/APICloud/Create+and+Publish+an+API
[6]https://docs.wso2.com/display/APICloud/Subscribe+to+and+Invoke+an+API

Comments

  1. API calls are the foundation of modern digital interactions, allowing different software systems to communicate and share data seamlessly. They're like the language that applications speak, enabling them to request and exchange information. These calls empower countless online services, from weather apps to social media, making them user-friendly and efficient. The reliability and speed of API calls are crucial, ensuring a smooth experience for users. As our digital world continues to expand, understanding and optimizing API calls remain pivotal for delivering responsive and interconnected software solutions.

    ReplyDelete

Post a Comment

Popular posts from this blog

WSO2 Cloud

Introduction WSO2 Cloud consists of three commercial cloud offerings namely the API cloud, Integration Cloud and the Identity Cloud. WSO2 Integration Cloud WSO2 Integration Cloud is a public hosted version of the powerful, 100% open-source WSO2 Enterprise Integrator. It allows you to host your cloud-to-cloud, cloud-to-on-premise integrations and API backends on a scalable cloud platform WSO2 API Cloud WSO2 API Cloud is an enterprise-ready, self-service platform that enables you to expose business capabilities as managed APIs and leverage off-the-shelf potential for advertising and selling business APIs. The API Cloud supports all aspects of an API’s lifecycle, from its creation to publication and retirement. The API Cloud is based on WSO2 API Manager , WSO2’s complete solution for designing and publishing APIs and managing a developer community. [2] WSO2 Identity Cloud WSO2 Identity Cloud leverages the functionality of WSO2 Identity Server’s identity and ac...

Exposing a SOAP service as a REST API

In this post i will be explaining how we can transform a SOAP based backend to receive requests in a restful manner through the WSO2 API Cloud. Steps. First log into the WSO2 Cloud and navigate to the API Cloud. In the API cloud select the option to add a new API. We will be creating an API to demonstrate an invocation to the backend soap service ws.cdyne.com/phoneverify/phoneverify.asmx?wsdl Give a name, context and version to the API and add a resource name with a GET Method. The resource name can be anything which you like since we will invoke the actual service usiing a custom sequence. Mention the URI template as indicated in the below screenshot. Next go to the implement tab. And select the endpoint type as HTTP/SOAP Endpoint and specify the endpoint as http://ws.cdyne.com/phoneverify/phoneverify.asmx. There is an important step we need to do here. We need to set the SOAP version for this request. In order to do that we need to select the advanced option ...

Configure WSO2 Identity Server for single sign on with Moodle - Part I

Introduction Moodle is a learning platform designed to provide educators, administrators and learners with a single robust, secure and integrated system to create personalized learning environments.[1]. This is commonly used in the education sector and there might be occurrences where it would require to use SAML to login to Moodle instead of the default basic authentication. For this we would need to have an Identity Provider capable of issuing such SAML tokens and Moodle configured to accept the tokens in order to do the authentication I will be discussing this in two parts. Part I - How to configure moodle for SSO with WSO2 Identity Server Part II - How to carry our user provisioning and attribute profile mapping with Moodle and WSO2 Identity Server Let's see how this can be achieved using a SAML authentication plugin provided by one login. Prerequisite  You need to have a working version of Moodle installed. If you want to try this tutorial from scratch you can ...