Tuesday, April 26, 2016

How to use App Manager Business Owner functionality ?

WSO2 App Manager new release (1.2.0) has introduced capability to define business owner for each application. (AppM-1.2.0  is yet to be released by the time this blog post is writing and you could download nightly build from here and tryout until the release is done.)

1. How to define business owners ?

Login as a admin user to admin-dashboard by accessing following URL.
https://localhost:9443/admin-dashboard

This will give you UI similar to bellow where you can define new business owners.


Click on "Add Business Owner" option to add new business owners.


All created business owners are listed in UI as follows, which allows you to edit or delete from the list.




2. How to associate business owner to application ?

You can login to Publisher by accessing the following URL to create new app.
https://localhost:9443/publisher 

In the add new web app UI, you should be able to see page similar to following, where you can type and select the business owner for the app.



Once the required data is filled and app is ready to publish to store, change the app life-cycle state to 'published' to publish app into app store.



Once the app is published, users could access app through the App Store by accessing the following URL.
https://localhost:9443/store

App users can find the business owner details in the App Overview page as shown bellow.





If you are using REST APIs to create and publish the apps, following sample command would help.

These APIs are protected with OAuth and you need to generate a oauth token before invoking APIs.

Register a OAuth app and generates consumer key and secret key
Request:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic YWRtaW46YWRtaW4=" -d  '{"clientName": "Demo_App", "grantType": "password refresh_token"}'  http://localhost:9763/api/appm/oauth/v1.0/register

Note: Authorization header should pass base64encoded(username:password) as the value in above request.

Response:
{"clientId":"1kaMrCWFr9NeT1VCfTxacI_Pu0sa","clientName":"Demo_App","callBackURL":null,"clientSecret":"YNkRA_30pwOZ6kNTIZC9B54p7LEa"}

Generate access token using above consumer/secret keys
Request:
curl -k -X POST -H "Authorization: Basic MWthTXJDV0ZyOU5lVDFWQ2ZUeGFjSV9QdTBzYTpZTmtSQV8zMHB3T1o2a05USVpDOUI1NHA3TEVh" -H "Content-Type: application/x-www-form-urlencoded" -d 'username=admin&password=admin&grant_type=password&scope=appm:read appm:administration appm:create appm:publish'  https://localhost:9443/oauth2/token

Note: Authorization header should pass base64encoded(clientId:clientSecret) as the value in above request.

Response:
{"access_token":"cc78ea5a2fa491ed23c05288f539b5f5","refresh_token":"3b203c859346a513bd3f94fc6bf202e4","scope":"appm:administration appm:create appm:publish appm:read","token_type":"Bearer","expires_in":3600}


Add new business owner
Request:
curl -X POST -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" -d '{"site": "http://wso2.com", "email": "beth@gmail.com", "description": "this is a test description", "name": "Beth", "properties": [{"isVisible": true,"value": "0112345678","key": "telephone"}]}' http://localhost:9763/api/appm/publisher/v1.1/administration/businessowner

Response:
{"id":1}


Create new App and define business owner as previously added business owner
curl -X POST -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" http://localhost:9763/api/appm/publisher/v1.1/apps/webapp -d '{
  "name": "TravelBooking",
  "version": "1.0.0",
  "isDefaultVersion":true,
  "displayName": "Travel Booking",
  "description": "description",
  "businessOwnerId":"1",
  "isSite": "false",
  "context": "/travel",
  "appUrL": "http://www.google.lk",
  "acsUrl": "",
  "transport": "http",
  "policyGroups": [
    {
      "policyGroupName": "policy1",
      "description": "Policy 1",
      "throttlingTier": "Unlimited",
      "userRoles": [
        "role1"
      ],
      "allowAnonymousAccess": "false"
    },
    {
      "policyGroupName": "policy2",
      "description": "Policy 2",
      "throttlingTier": "Gold",
      "userRoles": [
        "role2"
      ],
      "allowAnonymousAccess": "false"
    },
    {
      "policyGroupName": "policy3",
      "description": "Policy 3",
      "throttlingTier": "Unlimited",
      "userRoles": [
        "role3"
      ],
      "allowAnonymousAccess": "false"
    }
  ],
  "uriTemplates": [
    {
      "urlPattern": "/*",
      "httpVerb": "GET",
      "policyGroupName": "policy1"
    },
    {
      "urlPattern": "/*",
      "httpVerb": "POST",
      "policyGroupName": "policy2"
    },
    {
      "urlPattern": "/pattern1",
      "httpVerb": "POST",
      "policyGroupName": "policy3"
    }
  ]
}'

Response:
{"AppId": "78012b68-719d-4e14-a8b8-a899d41dc712"}


Change app lifecycle state to 'Published'
curl -X POST -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" http://localhost:9763/api/appm/publisher/v1.1/apps/webapp/change-lifecycle?appId=78012b68-719d-4e14-a8b8-a899d41dc712&action=Submit%20for%20Review

curl -X POST -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" http://localhost:9763/api/appm/publisher/v1.1/apps/webapp/change-lifecycle?appId=78012b68-719d-4e14-a8b8-a899d41dc712&action=Approve

curl -X POST -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" http://localhost:9763/api/appm/publisher/v1.1/apps/webapp/change-lifecycle?appId=78012b68-719d-4e14-a8b8-a899d41dc712&action=Publish

Retrieve App info in store
Request:
curl -X GET -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" http://localhost:9763/api/appm/store/v1.1/apps/webapp/id/78012b68-719d-4e14-a8b8-a899d41dc712

Response:
{"businessOwnerId":"1","isSite":"false","isDefaultVersion":true,"screenshots":[],"customProperties":[],"tags":[],"rating":0.0,"transport":["http"],"lifecycle":"WebAppLifeCycle","lifecycleState":"PUBLISHED","description":"description","version":"1.0.0","provider":"admin","name":"TravelBooking1","context":"/travel1","id":"78012b68-719d-4e14-a8b8-a899d41dc712","type":"webapp","displayName":"Travel Booking"}

Retrieve business owner details
Request:
curl -X GET -H "Authorization: Bearer cc78ea5a2fa491ed23c05288f539b5f5" -H "Content-Type: application/json" http://localhost:9763/api/appm/store/v1.1/businessowner/1

Response:
{"site":"http://wso2.com","email":"beth@gmail.com","description":"this is a test description","name":"Beth","properties":[{"isVisible":true,"value":"0112345678","key":"telephone"}],"id":1}