Skip to main content

Preface

This document describes how to evaluate FAPI-compliant authorization flow and API request using an an Authlete service, that has been configured with settings described in Financial-grade API (FAPI) Basics (hereinafter “FAPI Basics”), and other components including Authlete’s reference implementations. Fapi With Ref Impl

Prerequisites

Before doing this, you are expected to have knowledge of OpenID Connect and Authlete by running through the following tutorial. You also need to have an Authlete service that has been configured with settings in accordance with FAPI Basics below. Run the instructions (A complete example walk through) in the document to make sure that your Authlete service works properly. The following software components are used in this tutorial. Prepare your lab environment that can execute them.
  • Required for this tutorial
  • Reommended, but you can choose other alternative tools
    • Apache HTTP Server (hereinafter “Apache”): A reverse proxy for authorization server and resource server
    • curl: An API client
    • OpenSSL: A tool to generate private keys and public key certificates

Configuring an authorization server

In this section, we will cover the following tasks:
  • Deploying a java-oauth-server package
  • Testing connection
The diagram below illustrates components configured in this section. A Web browser and curl send requests to an authorization server (java-oauth-server) whose endpoint is http://localhost:8080. Java Oauth Server 01

Configuring java-oauth-server

We will download and configure java-oauth-server. Detailed instructions are described in its document.

Downloading the source

Download java-oauth-server using git command.

Configuration

Edit the following entries in its configuration file, authlete.properties. Put the API key and the secret of your Authlete service that has been configured in accordance with FAPI Basics.

Starting the server

Start java-oauth-server using mvn command.

Test

Connect to http://localhost:8080 using a Web browser and the following page should be displayed. Java Oauth Server 02

Executing FAPI authorization flow (1)

Generate a request object in accordance with instructions in FAPI Basics and craft an authorization request using the object. The following values are used in this tutorial.
  • Authorization request (replace the values of client_id (1756...3766) and request (eyJr...YifQ.ewoi...iCn0.ztl2...tjAA) with yours determined above)
Enter the crafted request string (URL) to your Web browser’s location field. Java Oauth Server 03 An authorization page should be displayed. Enter john / john to Login ID / Password fields and click Authorize button. Java Oauth Server 04 Your Web browser will attempt (and fail) to connect https://client.example.org/cb/example.com/#code=... and show an error page stating that the host client.example.org doesn’t exist. Java Oauth Server 05

Authorization response

Copy the URL of the error page like below.
Extract code parameter in the URL.

Token request

Let’s craft a token request that contains the value of code (0Io2...sdkQ for example) and send it to java-oauth-server’s token endpoint (/api/token). In this section, we will try to do client authentication using client_id / client_secret as follows. Replace values of these parameters with yours that have been automatically generated during FAPI Basics.

Token response

You will receive a token response like this:
Java Oauth Server 06 That means:
  • java-oauth-server was unable to extract any client certificates from the token request as no mutual TLS connection has been established between the client (curl command in this tutorial) and java-oauth-server
  • Thus java-oauth-server didn’t include any client certificates in a request to Authlete’s (/auth/token API)
  • So Authlete couldn’t issue any certificate-bound access tokens and made a response with A244308 error
In the next section, we will add a reverse proxy to accept client certificates from clients to solve the error.

Enabling TLS for the authorization server

In this section, we will cover the following tasks:
  • Configuring a reverse proxy
  • Configuring a client
The diagram below illustrates components configured in this section. In the previous section, both Web browsers and clients connect directly to java-oauth-server (http://localhost:8080). The destination will be switched to Apache (https://as.example.com:8443) that resides in front of the server as a reverse proxy. On the client side, curl will attempt to connect to Apache using a client certificate to get authenticated. Java Oauth Server 11

Configuring a reverse proxy (1)

FQDN settings

Add the following entry to /etc/hosts so that both Web browsers and clients can find Apache to be installed in your lab environment, using as.example.com as FQDN.

Installing Apache

Install Apache in your lab environment.
This tutorial uses /usr/local/etc/httpd directory as the primary location of Apache’s configuration files.

Preparing a server certificate

Creating a private key and a public key certificate

Create an RSA private key and a public key certificate for Apache, using openssl command.
Two files, server.key (a private key) and server.crt (a public key certificate) are created.

Deploying the private key and the public key certificate

Deploy these two files to arbitrary location in your lab environment. This tutorial copies them under /usr/local/etc/httpd directory.

Configuring TLS for Apache

httpd.conf

We will configure basic Apache settings to:
  • Disable listening port 8080 (as java-oauth-server uses it)
  • Enable mod_proxy and mod_ssl related modules (to get Apache working as a reverse proxy and accepting TLS connection)
Actual changes to the configuration file, httpd.conf are as follows. TLS related settings are to be included from another file (extra/httpd-ssl.conf).

extra/httpd-ssl.conf

In this tutorial, we configure TLS and reverse proxy settings to:
  • Use as.example.com as its server name (while its listening port (8443) unchanged)
  • Meet the FAPI provisions (by using TLS 1.2 and limited sets of cypher suites)
  • Include a client certificate in X-Ssl-Cert header (so that /api/token endpoint of java-oauth-server can extract the value and include it in a request to Authlete API (/auth/token API), if it is set in the request from the reverse proxy)
  • Work as a reverse proxy that forwards requests accepted at https://as.example.com:8443/ to http://localhost:8080/ (java-oauth-server)
Changes to the configuration file, extra/httpd-ssl.conf are as follows.

Starting Apache

Start the Apache using apachectl command.
Once it’s started, connect to https://as.example.com:8443 using your Web browser and confirm if the content is the same as http://localhost:8080, the top page of java-oauth-server. In the next section, we wlll prepare a private key and a public key certificate for a client (curl) that makes a token request.

Settings for a client

Preparing a client certificate

Creating an RSA private key and a public key certificate

Execute openssl command as follows to create a private key and a public key certificcate.
Two files, client.key (a private key) and client.crt (a public key certificate) are created. We will use them to make token requests with curl.

Authorization request and response

Make an authorization request in the same way as Executing FAPI authorization flow (1). Extract a value of code parameter from an authorization response. The value in this tutorial is as follows.

Token request

Craft a token request and send it to the token endpoint of java-oauth-server (/api/token). The different parts from the previous example (Executing FAPI authorization flow (1)) are:
  • Endpoint URL: using https://as.example.com:8443 instead of http://localhost:8080
  • Client authentication method: using the private key (client.key) and the public key certificate (client.crt) instead of client_secret
Thus the curl command to be executed is like below. (replace the values of client_id and code with appropriate ones in your lab environment)

Token response

You should receive a token response like below.
Now you have successfully got an access token (nbN3...LAU8 for example) through mutual TLS connection. In the backstage, Authlete has made the access token bound to the client certificate. In the next section, we will attempt to make an API request with an access token to a resource server.

Configuring a resource server

In this section, we will cover the following tasks:
  • Deploying a java-resource-server package
  • Testing connection
The diagram below illustrates components configured in this section. Java Resource Server 01

Configuring java-resource-server

We will download and configure java-resource-server. Instructions are described in its document.

Downloading the source

Download java-resource-server using git command.

Configuration

Edit the following entries in its configuration file, authlete.properties. Put the API key and the secret that are the same values as specified for java-oauth-server.

Starting the server

Start java-resource-server using mvn command.

Test

Connect to http://localhost:8081 using a Web browser and the following page should be displayed. Java Resource Server 02

Executing an API request (1)

Let’s try to make an API request with an access token to “Country Endpoint” of java-resource-server, using curl command. The access token can be obtained by doing the flow described in Executing FAPI authorization flow (2). In this tutorial, the following value is used.
Make a request with the access token specified in Authorization header. The examples below show the request and the subsequent response. -v option is added to curl command so that it can enable verbose output especially header information.
That response means:
  • java-resource-server was unable to extract any client certificates from the token request as no mutual TLS connection has been established between the client (curl command) and java-resource-server
  • Thus, java-resource-server didn’t include any client certificates in a request to Authlete’s /auth/introspection API
  • So, Authlete couldn’t check the binding between the access token and its corresponding client certificate and made a response with A065304 error
In the next section, we will configure additional settings for the reverse proxy.

Enabling TLS for the resource server

In this section, we will cover the following tasks that are basically the same as the settings for java-oauth-server done in the former section:
  • Additional settings for the reverse proxy
The diagram below illustrates components configured in this section. curl will attempt to connect to Apache (https://rs.example.com:8443) using a client certificate to get authenticated. Java Resource Server 11

Configuring a reverse proxy (2)

FQDN settings

Modify the entry that has been added to /etc/hosts during Configuring a reverse proxy (1) so that curl can connect to Apache using rs.example.com.

Configuring TLS for Apache

extra/httpd-ssl.conf

Add the following entries to the extra/httpd-ssl.conf file. These settings, the same as Configuring a reverse proxy (1) except the server name and destinations of the reverse proxy, are to:
  • Declare these settings are applied to rs.example.com:8443
  • Meet the FAPI provisions (by using TLS 1.2 and limited sets of cypher suites)
  • Include a client certificate in X-Ssl-Cert header (so that /api/country endpoint of java-resource-server can extract the value and include it in a request to Authlete API (/auth/introspection API), if it is set in the request from the reverse proxy)
  • Work as a reverse proxy that forwards requests accepted at https://rs.example.com:8443/ to http://localhost:8081/ (java-resource-server)
The additional entries to the configuration file, extra/httpd-ssl.conf are as follows.

Starting Apache

Stop and start the Apache using apachectl command.
After the restart, connect to https://rs.example.com:8443 using your Web browser and confirm if the content is the same as http://localhost:8081, the top page of java-resource-server.

Executing an API request (2)

Make an API request using curl command in the same way as Executing an API request (1). The access token can be obtained by doing the flow described in Executing FAPI authorization flow (2). In this tutorial, the following value is used.
Make a request with the access token specified in Authorization header. The different parts from the previous example (Executing an API request (1)) are:
  • Endpoint URL: using https://rs.example.com:8443 instead of http://localhost:8081
  • Client authentication method: using the private key (client.key) and the public key certificate (client.crt) in addition to the access token
Thus the curl command to be executed is like below.
You should receive a successful API response like below.
Java Resource Server 12 It means that:
  • java-resource-server extracted the client certificate from the mutual TLS connection and sent it to Authlete,
  • Authlete validated the binding between the client certificate and the access token, and
  • java-resource-server has processed the API request as expected.

Conclusion

In this tutorial, we confirmed FAPI-compliant authorization flow and API request using a FAPI-enabled Authlete service, reference implementations (java-oauth-server and java-resource-server) and a reverse proxy.