SlideShare a Scribd company logo
BUILDING A WEB API
 PLATFORM WITH OPEN
SOURCE OAUTH 2.0, REST,
      AND NOSQL

      SESSION 6946
      JAVAONE 2012
About the speakers
   Raymond Feng
          Software Engineer – Shutterfly, Inc.
     Staff

     Member – Apache Software Foundation

     Committer – Apache Tuscany, Wink, Amber

     Co-author – Tuscany SCA In Action
Agenda
   Why a Web API platform
   The key components of Web API platform
    stack
     OAuth  2.0
     Http Reverse Proxy

     Metrics

     API discovering, exploring and playing

   Q&A
Overview of a Web API
Platform
Why a Web APIs platform?
   Why Web API?
     A great way to build the ecosystem
     For some companies, APIs = products

     Proliferation of mobile clients

     Universal access for internal systems/web or mobile
      fronts/third party apps
   This talk is about the platform/infrastructure
    behind the curtain to support Web API calls.
    It’s NOT about Web API
    design/development/security.
What’s behind the scene?
   What’s behind an oAuth 2.0 protected REST
    API call?
     GET
      https://api.<mycompany>.com/me/albums?acces
      s_token=<oAuth 2.0 access token>
     POST
      https://api.<mycompany>.com/me/albums?acces
      s_token=<oAuth 2.0 access token>
       Content-Type:  application/json
       Accept: application/json
       Request body: {“name”: “Summer 2012”}
A Web API Platform
                                        QoS plugins




                                                            HTTP Reverse Proxy
                                           Auth                                   Protected
                                                                                    Protected
                                                                                  Resource
                                                                                    Resource
                                         Metrics
  Client
    Client
Application                             Throttling
 Application

                                        Mediation
                                                                                 User Sign-in
                                                                                    Page

                                             …



               Infrastructure
                                     Distributed data grid
                           (service registry, metrics, quota/usage)

                                                                                 Persistenc
                                           Security                                  e
                  (Identity management, client application registration, user
                     authentication, token management, resource ACLs)
Key components
   Authentication/Authorization (oAuth 2.0)
   Reverse proxy (API dispatching)
   Mediation
   Monitoring
   Analytics
   Backend infrastructure
       Client/Token management
       Service registry
       Metrics aggregation
       Metrics visualization
   Developer portal
       Application registration
       Dashboard
       API documentation
       API playground
API invocation flow
   An API request (REST/JSON) comes in using
    HTTPS
   Threat detection
   Authentication (oAuth 2.0 access_token)
   Authorization (token – scopes – resources)
   Rate limiting
   Caching
   Mediation
   Routing
   Analytics
   API Logic
oAuth 2.0
oAuth 2.0
   Based on Apache Amber which implements
    the latest oAuth 2.0 spec
     http://tools.ietf.org/html/draft-ietf-oauth-v2-31

     http://incubator.apache.org/amber/

   Additional SPIs are identified for oAuth 2.0
    related metadata management and integration
    with the security infrastructure
oAuth 2.0 concepts
   OAuth defines four roles:
     resource owner: An entity capable of granting access
      to a protected resource (e.g. end-user).
     resource server: The server hosting the protected
      resources, capable of accepting and responding to
      protected resource requests using access tokens.
     client: An application making protected resource
      requests on behalf of the resource owner and with its
      authorization.
     authorization server: The server issuing access
      tokens to the client after successfully authenticating
      the resource owner and obtaining authorization.
oAuth 2.0 flows/grant types
   An authorization grant is a credential
    representing the resource owner's
    authorization (to access its protected
    resources) used by the client to obtain an
    access token.
   oAuth 2.0 specification defines four grant
    types:
     authorization   code
     implicit

     resource  owner password credentials
     client credentials
User cases: Trusted client
applications
   Trusted clients include:
     Internal  applications (running at the server side or
      client side)
     Mobile clients

   Mapping to oAuth 2.0
     Clientcredentials for access token (super user)
     Resource owner password credentials for access
      token (run as the “resource owner”)
Use cases: Third party
applications
   We plan to roll out web APIs to 3rd party
    applications
   oAuth 2.0 will be used as the
    authentication/authorization mechanism
   Mapping to oAuth 2.0
     Authorization   code flow
     Implicit grant flow
oAuth 2.0 SPI – Client
registration
   Client applications will be registered
     Contact  e-mail
     Application name/description

     Callback URIs

     Authentication scheme
oAuth 2.0 SPI – resource ACL
      Determine if a resource is protected
        Public

        Client-id
                specific
        Resource-owner specific

      Who are the resource owners?
      Scopes of the access
{"scope": "media",                      {"id": "media_resource",
"description": "Media",                 "operations": [ "ALL”],
"expiresIn": 604800,                    "path": "/media",
"requiredAccessLevel": 1,               "scopes": [ "media”]
"resourceOwnerAuthorizationRequired":   }
false
}
oAuth 2.0 SPI – Authentication &
Authorization
   Make sure a client is registered
   Make sure a token/code is valid
   Authenticate a client using
    client_id/client_secret
   Authenticate a resource owner using user
    name/password
   Check the token against the protected
    resources (ACL)
   Establish the principal/subject
oAuth 2.0 SPI – Token
Management
   Generate access/refresh tokens for a given client,
    resource owner, and scopes
   Generate authorization codes for a given client,
    resource owner, and scopes
   Look up the token metadata based on the token
    string
   Look up the authorization code metadata based
    on the code string
   Expiration
   Refresh tokens
   MongoDB as the backend store for tokens
oAuth 2.0 infrastructure
                              Client                  Client
            Authorization                           Registration       Client
                            Registration
               Server                                Manager        Registrations
                             Endpoint
 Resourc
 e Owner



                            Authorization                              Users
                                                    Authenticator
                             Endpoint                                (Resource       Protected
                                                                      Owners)       Resources
  User       Internet                                                                (such as
  Agent                                                                             user media
(browser)                                                                           or address
                               Token
                              Endpoint                 Token        Tokens and         book)
                                                      Manager       Authorization
                                                                       Codes

                                                     Resource
 Client                                               Access
                                                     Manager         Resource
                             oAuth 2.0
                                                                    Permissions
                             Resource                                and Scope
                               Filter                                Definitions


                                            HTTP
            Resource                        proxy
             Server
Mapping oAuth 2.0 scopes
                     Scope
                       Scope
                         Scope


                                                                    Protected
                                                                      Protected
                                                                    Resource
 oAuth 2.0                                                              Protected
                                                                      Resource
   token                              GET /services/addressbook/…
                                                                        Resource
                                      POST/services/addressbook/…
                       Client
                                         GET /services/media/…

                                                  …

                                                  …




                      Resource
                       Owner




      See an example at:
      http://developers.facebook.com/docs/reference/api/permissions/
oAuth 2.0 metadata model
Client/Resource management
(administrative)
   We need to have UI to
     manage   the resource endpoints (URI patterns
      and HTTP operations)
     define oAuth 2.0 scopes to map to a list of
      resource access permissions
     Manage client applications (enable/disable,
      setting quota, …)
     Manage access tokens/authorization codes
Dashboard
   Monitor the API usages (administrative)
     By client id
     By user id
     By resource URIs
     By timeline

   Let developers see their client applications
    (developer)
     Registrations
     Usages
     Granted   permissions
REST APIs for API
management
   Get the list of defined scopes
   Display a scope
   Get the list of defined resources
   Display a token
   Display an authorization code
   Display a client registration
   Get the list of registered clients for a given user
   List tokens by client id/user id
   List authorization codes by client id/user id
   List granted permissions
Performance
oAuth 2.0
HTTP reverse proxy
   DO NOT deploy the services on the api server
    directly
   API server dispatches API calls to the back-
    end services
   Open source tools:
     Apache   http components: http://hc.apache.org/
HTTP reverse proxy – connection
management
   HTTP connection pool
     Persistent   connections (keep-alive)
       Check the keep alive settings at the backend web
       servers
     Chunked     transfer encoding support
       Some    Nginx servers don’t support chunked mode
     Make  sure the http entity is “consumed” so that
     the http connection will be released back to the
     pool
   http://hc.apache.org/httpcomponents-client-
    ga/tutorial/html/connmgmt.html
Routing/Proxying
   URL mapping  service registry
   URL templating
    <uriMapping>
       <source>/addressbook/{uid}</source>
       <target>http://backend.xyz.com/services/addressbook/{uid}</target>
    </uriMapping>
     api.xyz.com/addressbook/me/contatcs
       The
          “me” or “self” will be replaced with the resource
       owner from the oAuth 2.0 access token
Sync vs. Async
   Sync:
       Servlet 2.5 and Apache HTTP client 4.x
   Async:
       Servlet 3.0 async filter (Tomcat 7.0.x or Jetty 8.x)
       Apache HttpAsyncClient 4.0 beta 2
    final AsyncContext asyncContext =
    request.startAsync();
               asyncContext.start(new Runnable() {
          public void run() {
                     asyncDispatch(asyncContext, target);
                 }
           });
Java vs. Node.js
   Which one is better?
     Overhead

     Scalability

   Servlet 2.5 sync mode + Apache http client
   Servlet 3.0 async mode + Apache http async
    client
   Node.js event-driven mode + http
Mediations
   Some examples:
     Protocol/data    translation
       XML    JSON
     API   tracking
       https://github.com/codahale/metrics
       http://graphite.wikidot.com/

     Analytics

     CORS    enablement
API discovery and
documentation
API discovery and
documentation
   Some apis/tools that help developers to discover
    and explore the apis
     A spec to describe the apis (urls, methods,
      input/output/exception data model)
     A UI to discover and explore the apis
     Some integration with the api implementation stacks
      such as JAX-RS to introspect the api signatures
     Client code generation tool

   Open source tools
     http://swagger.wordnik.com/
     https://developers.google.com/discovery/
Swagger UI
Q&A
   Thank you!

More Related Content

Viewers also liked

Intro to API Security with Oauth 2.0
Intro to API Security with Oauth 2.0Intro to API Security with Oauth 2.0
Intro to API Security with Oauth 2.0
Functional Imperative
 
Google Map Code
Google Map CodeGoogle Map Code
Google Map Code
Web Development Phoenix
 
0010 la era_de_los_smart_devices
0010 la era_de_los_smart_devices0010 la era_de_los_smart_devices
0010 la era_de_los_smart_devices
GeneXus
 
Teacher Dashboard for Google Apps overview june 2011
Teacher Dashboard for Google Apps overview june 2011Teacher Dashboard for Google Apps overview june 2011
Teacher Dashboard for Google Apps overview june 2011
Hapara
 
OAuth: The Next Big Thing in Security
OAuth: The Next Big Thing in SecurityOAuth: The Next Big Thing in Security
OAuth: The Next Big Thing in Security
Apigee | Google Cloud
 
Patterns and Practices in Mobile SSO
Patterns and Practices in Mobile SSOPatterns and Practices in Mobile SSO
Patterns and Practices in Mobile SSO
WSO2
 
Jlook open api server platform
Jlook open api server platformJlook open api server platform
Jlook open api server platform
HongSeong Jeon
 
Jlook open api platform-sysdevguide
Jlook open api platform-sysdevguideJlook open api platform-sysdevguide
Jlook open api platform-sysdevguide
HongSeong Jeon
 
Open platform
Open platformOpen platform
Open platform
Joseph Chiang
 
Nuclear power station(Components)
Nuclear power station(Components)Nuclear power station(Components)
Nuclear power station(Components)
Parth Patel
 
Api barcelona
Api barcelonaApi barcelona
Api barcelona
gmenvielle
 
I want to be an efficient developer - APIdays Barcelona version
I want to be an efficient developer - APIdays Barcelona versionI want to be an efficient developer - APIdays Barcelona version
I want to be an efficient developer - APIdays Barcelona version
Quentin Adam
 
usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)
usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)
usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)
javier ramirez
 
Enhance the browser_experience
Enhance the browser_experienceEnhance the browser_experience
Enhance the browser_experience
HTML5 Spain
 
Patent wars, Innovation, Roads
Patent wars, Innovation, RoadsPatent wars, Innovation, Roads
Patent wars, Innovation, Roads
Jonathan Bourguignon
 
The Lincoln Institue - 10 Ways to Regenerate America's Legacy Cities
The Lincoln Institue - 10 Ways to Regenerate America's Legacy CitiesThe Lincoln Institue - 10 Ways to Regenerate America's Legacy Cities
The Lincoln Institue - 10 Ways to Regenerate America's Legacy Cities
Cassidy Swanson
 
APIfying the Web with import.io (at APIdays mediterranea)
APIfying the Web with import.io (at APIdays mediterranea)APIfying the Web with import.io (at APIdays mediterranea)
APIfying the Web with import.io (at APIdays mediterranea)
Ignacio Elola Villar
 
AIL Platform APIDays Mediterranea
AIL Platform APIDays MediterraneaAIL Platform APIDays Mediterranea
AIL Platform APIDays Mediterranea
Joan Protasio
 
Build a Restfull app using drupal
Build a Restfull app using drupalBuild a Restfull app using drupal
Build a Restfull app using drupal
Alvaro J Hurtado Villegas
 
Open platform/API overview
Open platform/API overviewOpen platform/API overview
Open platform/API overview
Samsung Electronics
 

Viewers also liked (20)

Intro to API Security with Oauth 2.0
Intro to API Security with Oauth 2.0Intro to API Security with Oauth 2.0
Intro to API Security with Oauth 2.0
 
Google Map Code
Google Map CodeGoogle Map Code
Google Map Code
 
0010 la era_de_los_smart_devices
0010 la era_de_los_smart_devices0010 la era_de_los_smart_devices
0010 la era_de_los_smart_devices
 
Teacher Dashboard for Google Apps overview june 2011
Teacher Dashboard for Google Apps overview june 2011Teacher Dashboard for Google Apps overview june 2011
Teacher Dashboard for Google Apps overview june 2011
 
OAuth: The Next Big Thing in Security
OAuth: The Next Big Thing in SecurityOAuth: The Next Big Thing in Security
OAuth: The Next Big Thing in Security
 
Patterns and Practices in Mobile SSO
Patterns and Practices in Mobile SSOPatterns and Practices in Mobile SSO
Patterns and Practices in Mobile SSO
 
Jlook open api server platform
Jlook open api server platformJlook open api server platform
Jlook open api server platform
 
Jlook open api platform-sysdevguide
Jlook open api platform-sysdevguideJlook open api platform-sysdevguide
Jlook open api platform-sysdevguide
 
Open platform
Open platformOpen platform
Open platform
 
Nuclear power station(Components)
Nuclear power station(Components)Nuclear power station(Components)
Nuclear power station(Components)
 
Api barcelona
Api barcelonaApi barcelona
Api barcelona
 
I want to be an efficient developer - APIdays Barcelona version
I want to be an efficient developer - APIdays Barcelona versionI want to be an efficient developer - APIdays Barcelona version
I want to be an efficient developer - APIdays Barcelona version
 
usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)
usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)
usable rest apis, by Javier Ramirez from teowaki (Apidays Mediterranea)
 
Enhance the browser_experience
Enhance the browser_experienceEnhance the browser_experience
Enhance the browser_experience
 
Patent wars, Innovation, Roads
Patent wars, Innovation, RoadsPatent wars, Innovation, Roads
Patent wars, Innovation, Roads
 
The Lincoln Institue - 10 Ways to Regenerate America's Legacy Cities
The Lincoln Institue - 10 Ways to Regenerate America's Legacy CitiesThe Lincoln Institue - 10 Ways to Regenerate America's Legacy Cities
The Lincoln Institue - 10 Ways to Regenerate America's Legacy Cities
 
APIfying the Web with import.io (at APIdays mediterranea)
APIfying the Web with import.io (at APIdays mediterranea)APIfying the Web with import.io (at APIdays mediterranea)
APIfying the Web with import.io (at APIdays mediterranea)
 
AIL Platform APIDays Mediterranea
AIL Platform APIDays MediterraneaAIL Platform APIDays Mediterranea
AIL Platform APIDays Mediterranea
 
Build a Restfull app using drupal
Build a Restfull app using drupalBuild a Restfull app using drupal
Build a Restfull app using drupal
 
Open platform/API overview
Open platform/API overviewOpen platform/API overview
Open platform/API overview
 

More from Raymond Feng

Working with LoopBack Models
Working with LoopBack ModelsWorking with LoopBack Models
Working with LoopBack Models
Raymond Feng
 
Building a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 MinutesBuilding a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 Minutes
Raymond Feng
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
Raymond Feng
 
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Raymond Feng
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache Tuscany
Raymond Feng
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
Raymond Feng
 
Apache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsApache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIs
Raymond Feng
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache Tuscany
Raymond Feng
 
OSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyOSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache Tuscany
Raymond Feng
 

More from Raymond Feng (9)

Working with LoopBack Models
Working with LoopBack ModelsWorking with LoopBack Models
Working with LoopBack Models
 
Building a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 MinutesBuilding a Node.js API backend with LoopBack in 5 Minutes
Building a Node.js API backend with LoopBack in 5 Minutes
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
Building Flexible APIs for Web 2.x/Cloud Applications (JavaOne 2011 Session ...
 
RESTful SCA with Apache Tuscany
RESTful SCA with Apache TuscanyRESTful SCA with Apache Tuscany
RESTful SCA with Apache Tuscany
 
Data Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite ApplicationsData Binding Unleashed for Composite Applications
Data Binding Unleashed for Composite Applications
 
Apache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIsApache Tuscany 2.x Extensibility And SPIs
Apache Tuscany 2.x Extensibility And SPIs
 
OSGi Enablement For Apache Tuscany
OSGi Enablement For Apache TuscanyOSGi Enablement For Apache Tuscany
OSGi Enablement For Apache Tuscany
 
OSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache TuscanyOSGi Remote Services With SCA using Apache Tuscany
OSGi Remote Services With SCA using Apache Tuscany
 

Recently uploaded

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
Jakub Marek
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
Hiike
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
Jason Packer
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
Intelisync
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
fredae14
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 

Recently uploaded (20)

Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)Main news related to the CCS TSI 2023 (2023/1695)
Main news related to the CCS TSI 2023 (2023/1695)
 
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - HiikeSystem Design Case Study: Building a Scalable E-Commerce Platform - Hiike
System Design Case Study: Building a Scalable E-Commerce Platform - Hiike
 
Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024Columbus Data & Analytics Wednesdays - June 2024
Columbus Data & Analytics Wednesdays - June 2024
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 
A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024A Comprehensive Guide to DeFi Development Services in 2024
A Comprehensive Guide to DeFi Development Services in 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Recommendation System using RAG Architecture
Recommendation System using RAG ArchitectureRecommendation System using RAG Architecture
Recommendation System using RAG Architecture
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 

Building a Web API Platform with Open Source oAuth 2.0, REST, and NoSQL (JavaOne 2012)

  • 1. BUILDING A WEB API PLATFORM WITH OPEN SOURCE OAUTH 2.0, REST, AND NOSQL SESSION 6946 JAVAONE 2012
  • 2. About the speakers  Raymond Feng Software Engineer – Shutterfly, Inc.  Staff  Member – Apache Software Foundation  Committer – Apache Tuscany, Wink, Amber  Co-author – Tuscany SCA In Action
  • 3. Agenda  Why a Web API platform  The key components of Web API platform stack  OAuth 2.0  Http Reverse Proxy  Metrics  API discovering, exploring and playing  Q&A
  • 4. Overview of a Web API Platform
  • 5. Why a Web APIs platform?  Why Web API?  A great way to build the ecosystem  For some companies, APIs = products  Proliferation of mobile clients  Universal access for internal systems/web or mobile fronts/third party apps  This talk is about the platform/infrastructure behind the curtain to support Web API calls. It’s NOT about Web API design/development/security.
  • 6. What’s behind the scene?  What’s behind an oAuth 2.0 protected REST API call?  GET https://api.<mycompany>.com/me/albums?acces s_token=<oAuth 2.0 access token>  POST https://api.<mycompany>.com/me/albums?acces s_token=<oAuth 2.0 access token>  Content-Type: application/json  Accept: application/json  Request body: {“name”: “Summer 2012”}
  • 7. A Web API Platform QoS plugins HTTP Reverse Proxy Auth Protected Protected Resource Resource Metrics Client Client Application Throttling Application Mediation User Sign-in Page … Infrastructure Distributed data grid (service registry, metrics, quota/usage) Persistenc Security e (Identity management, client application registration, user authentication, token management, resource ACLs)
  • 8. Key components  Authentication/Authorization (oAuth 2.0)  Reverse proxy (API dispatching)  Mediation  Monitoring  Analytics  Backend infrastructure  Client/Token management  Service registry  Metrics aggregation  Metrics visualization  Developer portal  Application registration  Dashboard  API documentation  API playground
  • 9. API invocation flow  An API request (REST/JSON) comes in using HTTPS  Threat detection  Authentication (oAuth 2.0 access_token)  Authorization (token – scopes – resources)  Rate limiting  Caching  Mediation  Routing  Analytics  API Logic
  • 11. oAuth 2.0  Based on Apache Amber which implements the latest oAuth 2.0 spec  http://tools.ietf.org/html/draft-ietf-oauth-v2-31  http://incubator.apache.org/amber/  Additional SPIs are identified for oAuth 2.0 related metadata management and integration with the security infrastructure
  • 12. oAuth 2.0 concepts  OAuth defines four roles:  resource owner: An entity capable of granting access to a protected resource (e.g. end-user).  resource server: The server hosting the protected resources, capable of accepting and responding to protected resource requests using access tokens.  client: An application making protected resource requests on behalf of the resource owner and with its authorization.  authorization server: The server issuing access tokens to the client after successfully authenticating the resource owner and obtaining authorization.
  • 13. oAuth 2.0 flows/grant types  An authorization grant is a credential representing the resource owner's authorization (to access its protected resources) used by the client to obtain an access token.  oAuth 2.0 specification defines four grant types:  authorization code  implicit  resource owner password credentials  client credentials
  • 14. User cases: Trusted client applications  Trusted clients include:  Internal applications (running at the server side or client side)  Mobile clients  Mapping to oAuth 2.0  Clientcredentials for access token (super user)  Resource owner password credentials for access token (run as the “resource owner”)
  • 15. Use cases: Third party applications  We plan to roll out web APIs to 3rd party applications  oAuth 2.0 will be used as the authentication/authorization mechanism  Mapping to oAuth 2.0  Authorization code flow  Implicit grant flow
  • 16. oAuth 2.0 SPI – Client registration  Client applications will be registered  Contact e-mail  Application name/description  Callback URIs  Authentication scheme
  • 17. oAuth 2.0 SPI – resource ACL  Determine if a resource is protected  Public  Client-id specific  Resource-owner specific  Who are the resource owners?  Scopes of the access {"scope": "media", {"id": "media_resource", "description": "Media", "operations": [ "ALL”], "expiresIn": 604800, "path": "/media", "requiredAccessLevel": 1, "scopes": [ "media”] "resourceOwnerAuthorizationRequired": } false }
  • 18. oAuth 2.0 SPI – Authentication & Authorization  Make sure a client is registered  Make sure a token/code is valid  Authenticate a client using client_id/client_secret  Authenticate a resource owner using user name/password  Check the token against the protected resources (ACL)  Establish the principal/subject
  • 19. oAuth 2.0 SPI – Token Management  Generate access/refresh tokens for a given client, resource owner, and scopes  Generate authorization codes for a given client, resource owner, and scopes  Look up the token metadata based on the token string  Look up the authorization code metadata based on the code string  Expiration  Refresh tokens  MongoDB as the backend store for tokens
  • 20. oAuth 2.0 infrastructure Client Client Authorization Registration Client Registration Server Manager Registrations Endpoint Resourc e Owner Authorization Users Authenticator Endpoint (Resource Protected Owners) Resources User Internet (such as Agent user media (browser) or address Token Endpoint Token Tokens and book) Manager Authorization Codes Resource Client Access Manager Resource oAuth 2.0 Permissions Resource and Scope Filter Definitions HTTP Resource proxy Server
  • 21. Mapping oAuth 2.0 scopes Scope Scope Scope Protected Protected Resource oAuth 2.0 Protected Resource token GET /services/addressbook/… Resource POST/services/addressbook/… Client GET /services/media/… … … Resource Owner See an example at: http://developers.facebook.com/docs/reference/api/permissions/
  • 23. Client/Resource management (administrative)  We need to have UI to  manage the resource endpoints (URI patterns and HTTP operations)  define oAuth 2.0 scopes to map to a list of resource access permissions  Manage client applications (enable/disable, setting quota, …)  Manage access tokens/authorization codes
  • 24. Dashboard  Monitor the API usages (administrative)  By client id  By user id  By resource URIs  By timeline  Let developers see their client applications (developer)  Registrations  Usages  Granted permissions
  • 25. REST APIs for API management  Get the list of defined scopes  Display a scope  Get the list of defined resources  Display a token  Display an authorization code  Display a client registration  Get the list of registered clients for a given user  List tokens by client id/user id  List authorization codes by client id/user id  List granted permissions
  • 28. HTTP reverse proxy  DO NOT deploy the services on the api server directly  API server dispatches API calls to the back- end services  Open source tools:  Apache http components: http://hc.apache.org/
  • 29. HTTP reverse proxy – connection management  HTTP connection pool  Persistent connections (keep-alive)  Check the keep alive settings at the backend web servers  Chunked transfer encoding support  Some Nginx servers don’t support chunked mode  Make sure the http entity is “consumed” so that the http connection will be released back to the pool  http://hc.apache.org/httpcomponents-client- ga/tutorial/html/connmgmt.html
  • 30. Routing/Proxying  URL mapping  service registry  URL templating <uriMapping> <source>/addressbook/{uid}</source> <target>http://backend.xyz.com/services/addressbook/{uid}</target> </uriMapping>  api.xyz.com/addressbook/me/contatcs  The “me” or “self” will be replaced with the resource owner from the oAuth 2.0 access token
  • 31. Sync vs. Async  Sync:  Servlet 2.5 and Apache HTTP client 4.x  Async:  Servlet 3.0 async filter (Tomcat 7.0.x or Jetty 8.x)  Apache HttpAsyncClient 4.0 beta 2  final AsyncContext asyncContext = request.startAsync(); asyncContext.start(new Runnable() { public void run() { asyncDispatch(asyncContext, target); } });
  • 32. Java vs. Node.js  Which one is better?  Overhead  Scalability  Servlet 2.5 sync mode + Apache http client  Servlet 3.0 async mode + Apache http async client  Node.js event-driven mode + http
  • 33. Mediations  Some examples:  Protocol/data translation  XML  JSON  API tracking  https://github.com/codahale/metrics  http://graphite.wikidot.com/  Analytics  CORS enablement
  • 35. API discovery and documentation  Some apis/tools that help developers to discover and explore the apis  A spec to describe the apis (urls, methods, input/output/exception data model)  A UI to discover and explore the apis  Some integration with the api implementation stacks such as JAX-RS to introspect the api signatures  Client code generation tool  Open source tools  http://swagger.wordnik.com/  https://developers.google.com/discovery/
  • 37. Q&A  Thank you!