apis for api management: consume and develop apps

17
APIs for API Management: Consume and Develop Apps Lakmali Baminiwatta Senior Software Engineer Tharindu Dharmarathna Associate Software Engineer

Upload: wso2-inc

Post on 07-Jan-2017

581 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: APIs for API Management: Consume and Develop Apps

APIs for API Management: Consume and Develop Apps

Lakmali BaminiwattaSenior Software Engineer

Tharindu DharmarathnaAssociate Software Engineer

Page 2: APIs for API Management: Consume and Develop Apps

● Introduction● Publisher REST API● Store REST API● Access Control and Security● Consume APIs and Develop APPs

■ Register Apps and Obtain Consumer Key/Secret■ OAuth Scopes■ Generate Access Token■ Invoke APIs

● Demo● Q & A

Page 3: APIs for API Management: Consume and Develop Apps

● WSO2 APIM 1.10.0 is released with a new REST API for API Management.

o Follows RESTFul Principleso Swagger API Definitiono Secured with OAutho Current version : v0.9

● Apps can be developed for API Management by consuming the REST API.

Page 4: APIs for API Management: Consume and Develop Apps

● RESTFul API for Publisher Operations

● Apps can be developed for API Publisher functionality by consuming the APIs

■ API for APIs , API for Tiers, API for Subscriptions, etc

● API Definition is documented with Swagger 2.0■ https://docs.wso2.com/display/AM1100/apidocs/publisher/

Page 5: APIs for API Management: Consume and Develop Apps

● RESTFul API for Store Operations

● Apps can be developed for API Explore/Consume functionality by consuming the APIs

■ Subscriptions API, APIs API, Tags Collection API, Tiers Collection API, etc

● API Definition is documented with Swagger 2.0■ https://docs.wso2.com/display/AM1100/apidocs/store/

Page 6: APIs for API Management: Consume and Develop Apps

● By default REST API is secured with OAuth 2.0■ Resources are protected with OAuth Scopes

● Pluggable security mechanism■ ex: XACML over Basic Authentication

Page 7: APIs for API Management: Consume and Develop Apps

1. Register the Application and obtain Consumer Key/Secret

● Dynamic Client Registration (DCR)● Create Service Providers

2. Store Consumer Key/Secret in the Application

3. Generate Token for required scopes● Prefered OAuth Grant type can be used

4. Invoke APIs with Access Token

Page 8: APIs for API Management: Consume and Develop Apps

● Dynamic Client Registration (DCR)■ DCR OAuth 2.0 Profile

● Endpoint for on-the-fly client registration

● Example : Different installations of an App can get different client ID/secret pairs at the installation.

■ WSO2 APIM exposes a DCR endpoint secured with Basic Authentication

Page 9: APIs for API Management: Consume and Develop Apps

{ "callBackURL": "https://localhost:9443/restapp", "jsonString":"{..}" //app details, "clientId": "HfEl1jJPdg5tbtrxhAwybN05QGoa", "clientSecret": "l6c0aoLcWR3fwezHhc7XoGOht5Aa"}

POST /client-registration/v0.9/registerAuthorization:Basic <Base64EncodedUserName:Pwd>

{ "callbackUrl": "https://localhost:9443/restapp", "clientName": "rest_api_store", "tokenScope": "Production", "owner": "admin", "grantType": "password refresh_token", "saasApp": true }

DC

R E

ndpo

int

1. Register Application

2. Respond with Client ID/Secret

Page 10: APIs for API Management: Consume and Develop Apps

● Create Service Provider■ Create a service provider and register the application as an

OAuth 2.0 application■ Specify App URL as the callback URL■ Specify allowed grant types for token generation

Page 11: APIs for API Management: Consume and Develop Apps

● API resources are protected by OAuth Scopes● Enable access control for resources by role

■ Scope to role mapping is stored in the registry (_system/config/apimgt/applicationdata/tenant-conf.json)

● API Definition shows required scopes to access an API resource

■ Ex:

● Need to obtain an Access token with required scopes

Resource Scope

POST /api apim:api_create

GET /api apim:api_view

Page 12: APIs for API Management: Consume and Develop Apps

● Decide suitable grant type for your App● Generate Access Token with selected grant type

○ Ex:■ Authorization Code Grant Type https://docs.wso2.

com/display/AM1100/Generating+Access+Tokens+with+Authorization+Code+-+Authorization+Code+Grant+Type

■ Password Code Grant Typecurl -k -d "grant_type=password&username=appuser&password=12@ws&scope=apim:api_view" -H "Authorization: Basic SGZFbDFqSlBkZzV0YnRyeGhBd3liTjA1UUdvYTpsNmMwYW9MY1dSM2Z3ZXpIaGM3WG9HT2h0NUFh" https://127.0.0.1:8243/token

Page 13: APIs for API Management: Consume and Develop Apps

● APIs can be invoked using the obtained access token ■ Ex: Retrieving APIs

curl -H "Authorization: Bearer <Access Token>" http://127.0.0.1:

9763/api/am/store/v0.9/apis

Page 14: APIs for API Management: Consume and Develop Apps

Authorization Server

2. Authorization Request sent to Authorization Server

App1. Login Request

3. Authorization Code received

4. Token Generation Request

3. Access Token received

User Agent

Page 15: APIs for API Management: Consume and Develop Apps

o Develop a sample app by consuming Store REST API

Page 16: APIs for API Management: Consume and Develop Apps
Page 17: APIs for API Management: Consume and Develop Apps