||
Skip to end of metadata
Go to start of metadata

Introduction

JSON Web Token (JWT) is a compact and URL-safe means of transferring claims between applications.nThis sample demonstrates how to share claims from WSO2 App Manager to applications using JSON Web Token (JWT). It uses a sample Web app named TravelBooking to demonstrate how claims that are added to a user in WSO2 App Manager can be transferred to a published app.

Prerequisites

  • Download WSO2 App Manager, and start the server.

  • Start the Web server (e.g. Apache Tomcat)

Building the sample

Follow the steps below to build the Travel booking app.

  1. Download the TravelBooking sample app ( travel-booking-1.0.war file).
  2. Copy the travel-booking-1.0.war file to <TOMCAT_HOME>/webapps/ directory, to host the file in the Web server.
  3. Restart the Web server. You can access the TravelBooking web app from your web browser using the following URL: http://<IP_ADDRESS>:8080/travel-booking-1.0/

Building from source

Alternatively, you can build the app by building the product source. Follow the steps below to download the source and build the app.

  1. Download the source code of the product using the following command.
    $ git clone https://github.com/wso2/product-app-manager/
  2. Navigate to <travel-booking>/Travel/ directory from the CLI, and build the source using the command: mvn clean install
  3. Copy the <travel-booking>/Travel/target/ travel-booking-1.0.war file to <TOMCAT_HOME>/webapps/ directory, to host the file in the Web server.
  4. Restart the Web server. You can access the TravelBooking web app from your web browser using the following URL: http://<IP_ADDRESS>:8080/travel-booking-1.0/

Executing the sample

Follow the steps below to execute the sample.

Adding claims to the user

Follow the steps below to add claims to the admin user in App Manager.

  1. Log in to the management console using the following URL with admin/admin credentials: https://<IP_ADDRESS>:9443/carbon/
  2. Click Configure, and then click Claim Management.
  3. Click http://wso2.org/claims, and then click Add New Claim Mapping.

  4. Add the claims, which are used in this sample by entering the following details.

    Display NameDescriptionClaim URIMapped Attribute(s)
    Zip Codezip code of the user's addresshttp://wso2.org/claims/zipcodezipcode
    Credit Card Numberuser's credit card numberhttp://wso2.org/claims/card_numbercard_number
    Credit Card Holder Namecredit card holder's name

    http://wso2.org/claims/card_holder

    card_holder
    Credit Card Expiration Datecredit card expiration date

    http://wso2.org/claims/expiration_date

    expiration_date

    For an example, follow the steps below to add the claim mapping for the zip code.

    • Enter the details as shown below, and click Add as shown below.
      creating new claimsYou view the new claim added to the available claim mappings list.

    • Click the corresponding Edit link of the Zip Code claim mapping you added.

    • Select the  Supported by Default  option, and click  Update   as shown in the below example.

      You will not be able to select the Supported by Default option when you add the claim in step 4 due to a known issue, which will be fixed in future releases.

    In addition to the above new claims, this sample uses the following claims that are available by default as shown below.

    • Address
    • Country
    • Email Address
    • First Name
    • Last Name
    claims available by defualt
  5. Follow the steps below for each of the above claims to update them.

    • Click the corresponding Edit link.
    • Select the Supported by Default checkbox, and click Update to add them to the user profile.

Updating the profile

Follow the steps below to update the profile by entering the values for the newly added claims.

  1. Log in to the management console using the following URL with admin/admin credentials: https://<IP_ADDRESS>:9443/carbon/
  2. Click  Configure , and then click  Users and Roles .
  3. Click Users, and then since you are logged in as admin, click User Profile link of the admin user.
  4. Enter the details as shown below, and click Update.
    update admin user profile

Creating the Web app

Follow the steps below to create a new Web app in App Publisher to publish the Travel Booking app.

Completing the Overview section

Follow the steps below to complete the first step of creating a new Web app.

  1. Log in to the App Publisher of WSO2 App Manager using the following URL:http://<IP_ADDRESS>:9763/publisher
  2. Click Add New Web Application, to add the TravelBooking Web app using the App Publisher. 

  3. Enter the details in the Overview section as shown below. For instructions on the Overview section of adding a Web app, see  Step 1 - Overview.

    create new Web app

Completing the Advanced Configuration section
  1. Click Advanced Configuration, and then click Claims.

  2. Follow the steps below to enter all claims as shown below. For instructions on specifying the claims in the Advanced Configuration section of adding a Web app, see  Step 4 - Single Sign On Configuration.

    • Select the claim URI from the Available Claims list.
    • Click Add Claim.

    add claims when publishing the app

  3. Click Create.

Publishing the Web app

Follow the steps below to publish the Web app in the App Publisher. For more instructions on publishing a Web app, see Web Application Lifecycle Management.

  1. In the All Web Applications list, click Submit for Review button corresponding to the app.
  2. Click Approve.
  3. Click Publish.

Subscribing to the Web app

Follow the steps below to subscribe to the Web app. For instructions on subscribing to a Web app, see Subscribing to Applications.

  1. Log in to the App Store of WSO2 App Manager using the following URL: http://<IP_ADDRESS>:9763/store
  2. Click on the image of the Web app.
  3. Click Subscribe Me.
  4. Click the Gateway Endpoint URL of the Web app as shown below.
    gateway endpoint URL

Viewing the added claims in the Web app

Follow the steps below to view the values of the claims automatically being added to the Web app.

  1. Log in to the app if you're not already logged it. You will be automatically logged in to this app if the single sign-on feature is enabled in WSO2 App Manager.
  2. Enter the details in the screen as shown below.
    travel booking app home page
  3. Click Proceed to Results button. The values you added for the claims will be filled automatically as shown below.
    traveller info auto fill
    payment details auto fill
  • No labels