The OAuth samples demonstrate OAuth 2.0 client, client registration, and client revocation. The samples show the basic implementation of JavaServer Pages (JSP) to write an OAuth client, an OAuth client registering servlet, and an OAuth client revocation servlet.
Here is what you should know about this sample before proceeding.
Approximately 15 minutes
This sample was tested most recently with WebSphere Application Server Version 8.5.0.1.
COPYRIGHT LICENSE: This information contains sample code provided in source code form. You may copy, modify, and distribute these sample programs in any form without payment to IBM for the purposes of developing, using, marketing or distributing application programs conforming to the application programming interface for the operating platform for which the sample code is written. Notwithstanding anything to the contrary, IBM PROVIDES THE SAMPLE SOURCE CODE ON AN "AS IS" BASIS AND IBM DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND ANY WARRANTY OR CONDITION OF NON-INFRINGEMENT. IBM SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR OPERATION OF THE SAMPLE SOURCE CODE. IBM HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS OR MODIFICATIONS TO THE SAMPLE SOURCE CODE.
Key phrases associated with this sample: "OAuth", "authorization"
Use clienttable.jsp as a sample management page to interface with the client provider object that is supplied to the OAuth provider component. The management page is tailored to interact with the default in-memory client provider sample, com.ibm.ws.security.oauth20.plugins.BaseClientProvider. Use custom management tools for other client repositories, like a database, or modify this page, as needed.
This JSP sample adds a registered client to an XML based client store. The Oauth service provider uses the client store XML file as a gatekeeper to decide if a client can make OAuth request to the service.
This JSP sample saves a registered oauth client to oauth database table.
Use this as a sample management page to interface with the Client Provider object supplied to the OAuth provider component. This page is tailored to interact with the default database client provider sample, <%=targetClientProvider%>. Use custom management tools for other client repositories, like a database, or modify this page to meet your needs.
To learn more about OAuth see the OAuth documentation in the WebSphere Application Server Information Center
You can find the source code for the OAuth Sample in the OAuth/src/ directory. The was.oauth.samples.war/WebContent sub-directory contains the source code for the sample.
Build the OAuth Sample Application
You do not need to build the OAuth Sample before using it. The following directions describe the steps to rebuild the OAuth Sample, with additional information for modifications.
The OAuth Sample is located in the following zip file directories:
Directory | Description |
---|---|
OAuth/src/ | Contains the sample source code for the sample. |
OAuth/installableApps/ | Contains the was.oauth.samples.ear file for sample. This directory is not modified if this sample is rebuilt. |
OAuth Sample/lib/ | Contains the Web archive (WAR) files, and the final was.oauth.samples.ear file for the Samples. This directory is created when this sample is rebuilt. |
To rebuild the OAuth Samples EAR file, perform the following steps:
export WAS_HOME=directory
set WAS_HOME=directory
export WAS_HOME=/opt/IBM/WebSphere/AppServer
scripts/buildsamples.sh
scripts\buildsamples.bat
The buildsamples scripts are located in the OAuth/scripts directory. The scripts set the appropriate class path information and run the Ant build utility. The Ant utility reads the build.xml files, which describe how to build the Samples. Refer to the Apache Ant Web site for additional documentation on the Ant utility.
Installing the OAuth Sample.ear file
Running the Sample
Before you begin, you must verify that the application server is running before running the clients. This sample is a standard J2EE application, and you can install on WebSphere Application Server. Prior to running this sample, you need to configure and enable OAuth feature (see the WebSphere Application Server Information Center for more information).
The sample code shows how to write a provider side application to register an OAuth client, how to remove client authorization, how to customize OAuth service provider, and how to write an OAuth client to work with OAuth service provider.
To run the OAuth sample from a WebSphere Application Server, perform the following steps:
http://localhost:9080/oauth2samples/<sample.jsp>
The following illustration shows the correctly running OAuth sample: