Git Product home page Git Product logo

apifest-client's Introduction

#ApiFest OAuth 2.0 Server and Mapping ApiFest consists of two main parts - the ApiFest OAuth 2.0 an OAuth 2.0 server and the ApiFest Mapping Server.

##ApiFest Mapping Server The ApiFest Mapping Server is for people who have APIs and want to expose them to the world in a safe and convenient way. The ApiFest Mapping Server is used to translate between the outside world and your internal systems. It helps you keep a consistent API facade.

###Features

  • mappings are described in xml;
  • can validate and authorize requests using the ApiFest OAuth20 Server;
  • out-of-the-box flexible mapping options - several versions support, different hosts to which API requests could be directed to;
  • easy to extend and customize;
  • customizable error messages and responses;
  • "online" change of all configurations;
  • unlimited horizontal scalability;

##ApiFest OAuth 2.0 Server The ApiFest OAuth 2.0 Server implements OAuth 2.0 server side as per http://tools.ietf.org/html/rfc6749. It enables the usage of access tokens in ApiFest Mapping Server.

###Features

  • register new client app;
  • generate access token using auth code;
  • generate access token using username and password - grant_type=password;
  • generate access token using client credentials - grant_type=client_credentials;
  • generate access token using refresh token - grant_type=refresh_token;
  • revoke access token;
  • validate access token;
  • pluggable storage (currently supports MongoDB and Redis);
  • unlimited horizontal scalability;

##ApiFest Mapping Server Quick start: 1. apifest.properties file

Here is a template of the apifest.properties file:

apifest.host=
apifest.port=
apifest.mappings=
apifest.global-errors=
token.validate.host=
token.validate.port=
connect.timeout=
custom.jar=
apifest.nodes=
hazelcast.password=

The path to the apifest.properties file should be set as a system variable:

-Dproperties.file

  • Setup the ApiFest Mapping Server host and port

The ApiFest Mapping Server can run on different hosts and ports. You can define ApiFest Mapping Server host and port in the apifest.properties file - apifest.host and apifest.port

By default, ApiFest Mapping Server will start on localhost:8080.

  • Setup mappings

The ApiFest Mapping Server needs information how to translate requests between the outside world and your internal system. That should be done in a mapping configuration file. The mapping configuration file is XML with schema accessible in the project under resources folder - schema.xsd.

Here is an example mapping file:

<mappings version="v0.1">
    <actions>
        <action name="ReplaceCustomerId" class="com.apifest.example.ReplaceCustomerIdAction"/>
        <action name="AddSenderIdInBody" class="com.apifest.example.AddSenderIdInBodyAction"/>
    </actions>
    <filters>
        <filter name="RemoveBalance" class="com.apifest.example.RemoveBalanceFilter"/>
    </filters>
    <backend host="127.0.0.1" port="8080"/>
    <endpoints>
        <endpoint external="/v0.1/me" internal="/customers/{customerId}" method="GET" authType="user" scope="basic">
            <action name="ReplaceCustomerId" />
            <filter name="RemoveBalance" />
        </endpoint>
        <endpoint external="/v0.1/me/friends" internal="/customers/{customerId}/friends" method="GET" authType="user" scope="basic">
            <action name="ReplaceCustomerId" />
        </endpoint>
		<endpoint external="/v0.1/users" internal="/users" method="GET" authType="user" scope="basic">
            <customProperties>
                <entry>
                    <key>com.name.project.package.RequiredAccessRights:value</key>
                    <value>VIEW_USERS,MANAGE_USERS</value>
                </entry>
            </customProperties>
		</endpoint>
        <endpoint external="/v0.1/countries/{countryId}" internal="/countries/{countryId}" method="GET" authType="client-app" varExpression="\w{3}$" varName="countryId"/>
        <endpoint external="/v0.1/mobile-auth/{mobileId}" internal="/mobile-auth/{mobileId}" method="GET" authType="user" varExpression="\d{6,15}$" varName="mobileId"/>
        <endpoint external="/v0.1/mobile-auth/{mobileId}" internal="/mobile-auth/{mobileId}" method="POST" authType="user" varExpression="\d{6,15}$" varName="mobileId"/>
    </endpoints>
    <errors>
        <error status="404" message='{"error":"resource not found"}' />
        <error status="405" message='{"error":"method is not allowed on that resource"}' />
        <error status="500" message='{"error":"ops...something wrong"}' />
    </errors>
</mappings>

XML specific tags explained:

  • version - is the version of your API this mapping file describes
  • actions - defines actions with name and class
  • filters - defines filters with name and class
  • backend - defines where your API is running, requests should be translated to that backend
  • endpoint - is a mapping between outer ednpoint and your API endpoint;
  • external - the endpoint visible to the world;
  • internal - your backend endpoint;
  • method - HTTP method;
  • scope - scope(s) of the endpoint;
  • authType - user for tokens obtained with user credentials, client-app for tokens obtained for client application;
  • action - defines action that will be executed before requests hit your API;
  • filter - defines filter that will be executed before responses from API are returned back;
  • varName - the name of the variable/s used in internal/external path (space delimited);
  • varExpression - regular expression (Java format) for varName (space delimited);
  • error - customize error responses - status attribute value defines the HTTP status for which message attribute value will be returned;
  • customProperties - defines properties specific to the endpoint

You can define as many mapping configuration files as many versions your API supports. The ApiFest Mapping Server will get all mappings files from the directory defined in the apifest.properties as

apifest.mappings

  • Setup Global errors

The ApiFest Mapping Server enables you to customize the error responses that are not related to a specific mapping configuration. For instance, when there is no mapping for a resource the default ApiFest Mapping Server response for 404 Status Code will be returned:

Status Code HTTP 404 Content-Type application/json {"error":"Not found"}

You can customize the content of that response using an XML file that describes your custom global errors. Here is an example file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<global-errors>
  <error status="401" message='{"error":"unauthorized"}'/>
  <error status="404" message='{"error":"resource not found"}'/>
</global-errors>

Using that customization, the response content when a resource is not mapped will be '{"error":"resource not found"}'. In order to setup errors customization in ApiFest Mapping Server, you should set the path to the configuration file in apifest.properties file as

apifest.global-errors

  • Setup token validation host and port

If access token is required for an endpoint, first it should be validated. The host and port where the ApiFest OAuth 2.0 Server runs are set by the following properties in the apifest.properties file -

token.validate.host and token.validate.port

  • Setup connection timeout

In order to setup connection timeout(in ms) to the backend, use the following property in the apifest.properties file -

connect.timeout

If you have custom request/response transformations, then you can set the path to your jar with transformations by the following property:

custom.jar

As ApiFest configurations are stored in distributed cache, you need to setup all other nodes (as comma-separated list of IPs) on which the ApiFest Mapping Server is running. To do that use the following property in the apifest.properties file -

apifest.nodes

As Hazelcast is used as a mapping configurations storage, you can set a password that will be used when Hazelcast is started in the ApiFest Mapping Server (otherwise the default Hazelcast password - dev-pass will be used). To set a password use the following property in the apifest.properties file -

hazelcast.password

3. Start the ApiFest Mapping Server

You can start the ApiFest Mapping Server with the following command:

java -Dproperties.file=[apifest_properties_file_path] -Dlog4j.configuration=file:///[log4j_xml_file_path] -jar apifest-0.1.0-jar-with-dependencies.jar

When the server starts, you will see: ApiFest Mapping Server started at [host]:[port]

apifest-client's People

Contributors

apostolterziev avatar mboyanov avatar rossitsaborissova avatar tangrila-bg avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

apifest-client's Issues

Refresh token grant type is currently not supported by the apifest-client

I'm trying to test the "refresh token" mechanism as described in the documentation under point: "4.5.4 Refresh token grant type" but the TokenRequest.java doesn't contain a 'refresh_token' attribute and the according Getter and Setter. Same story in the OAuthServer.java interface and the OAuthClient.java.
Could you provide this feature please? I don't want to use my local version of this client...
Thanks in advance!

Passthrough of the SSLContext to the ResteasyClient

The OAuthClient must urgently speak over https with the ApiFest server due to prevent a man-in-the-middle attack.
Initializing the OAuthClient with a 'https' URL will lead to a:

javax.net.ssl.SSLHandshakeException

What I don't want to do is to add my certificate to each JVM's trust store that is using the OAuthClient. A better approach would be a mechanism that allows me to provide a SSLContext to the OAuthClient, so my application would do the job.

Could you add a second constructor like

public OAuthClient(String oauthUrl, SSLContext sslContext)

or just a setter method for the SSLContext?

Maybe you can even implement a sophisticated mechanism for dealing with certifactes.jks?!
Just to get an idea of what I'm talking about, I've forked your client with a sample implementation.
You can use the whole code if you want: https://github.com/vmuth85/apifest-client

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.