SlideShare a Scribd company logo
Secure RESTful API
Automation With JavaScript

Jonathan LeBlanc (@jcleblanc)
Head of Developer Evangelism
PayPal North America
Automation?
What JavaScript Can Feel Like
JavaScript Challenges
The Same-Origin Policy
Keeping Private Keys Private
Not Providing a Hacked Experience
How Did We Used to Do It?
Server-side Proxies
Flash / iFrame Proxies
Private Token Storage
Securing Content Negotiation
A Modern Approach

OAuth 2
Tight Access Control

CORS
Easy Access Control
OAuth 2 User Agent Flow
User Agent Flow: Redirect
Prepare the Redirect URI
Authorization Endpoint
client_id response_type (token)
scope
redirect_uri

Browser Redirect
Redirect URI
User Agent Flow: Redirect
Building the redirect link
var auth_uri = auth_endpoint +
"?response_type=token" +
"&client_id=" + client_id +
"&scope=profile" +
"&redirect_uri=" + window.location;
$("#auth_btn").attr("href", auth_uri);
User Agent Flow: Hash Mod

Fetch the Hash Mod
access_token
refresh_token
expires_in

Extract Access Token
User Agent Flow: Hash Mod
Extracting the access token from the hash
http://site.com/callback#access_token=rBEGu1FQr5
4AzqE3Q&refresh_token=rEBt51FZr54HayqE3V4a&
expires_in=3600
var hash = document.location.hash;
var match = hash.match(/access_token=(w+)/);
User Agent Flow: Get Resources

Set Request Headers + URI
Resource Endpoint
Header: token type + access token
Header: accept data type

HTTPS Request
User Agent Flow: Get Resources
Making an authorized request
$.ajax({
url: resource_uri,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'OAuth ' + token);
xhr.setRequestHeader('Accept', 'application/json');
},
success: function (response) {
//use response object
}
});
CORS Easy Access Control
Cross Origin Issues and Options
Access to other domains / subdomains is
restricted (same origin policy)
JSONP to request resources across domains
Only supports HTTP GET requests

Cross-origin resource sharing (CORS)
Supports additional range of HTTP requests
Can you use it?
http://caniuse.com/cors
How Does it Work?
Site sends Origin header to server
OPTIONS /v1/oauth2/token HTTP/1.1
Origin: http://jcleblanc.com
Access-Control-Request-Method: PUT
Host: api.sandbox.paypal.com
Accept-Language: en-US
Connection: keep-alive
...
How Does it Work?
Server responds with matching
Access-Control-Allow-Origin header

Access-Control-Allow-Origin: http://jcleblanc.com
Access-Control-Allow-Methods: GET, POST, PUT

Content-Type: text/html; charset=utf-8
A Lil’ Bit O’ Automation
Uniform Interface Sub-Constraints
Resource Identification

Resources must be manipulated via
representations
Self descriptive messages
Hypermedia as the engine of
application state
Uniform Interface Sub-Constraints
Resource Identification

Resources must be manipulated
via representations
Self descriptive messages
Hypermedia as the engine of
application state
HATEOAS
How we Normally Consume APIs
Using HATEOAS to Automate
How HATEOAS Works
You make an API request
curl -v -X GET
https://api.sandbox.paypal.com/v1/payments/authoriz
ation/2DC87612EK520411B 
-H "Content-Type:application/json" 
-H "Authorization:Bearer
ENxom5Fof1KqAffEsXtx1HTEK__KVdIsaCYF8C"
"links": [
{
"href":"https://api.sandbox.paypal.com/v1/payments/
authorization/6H149011U8307001M",
"rel":"self",
"method":"GET"
},{
"href":"https://api.sandbox.paypal.com/v1/payments/
authorization/6H149011U8307001M/capture",
"rel":"capture",
"method":"POST"
},{
"href":"https://api.sandbox.paypal.com/v1/payments/
authorization/6H149011U8307001M/void",
"rel":"void",
"method":"POST"
}
]
Object Chaining
Interactions Should be Stateless
Send enough detail to not have to make another
request to the API
{ "id": "PAY-17S8410768582940NKEE66EQ",
"create_time": "2013-01-31T04:12:02Z",
"update_time": "2013-01-31T04:12:04Z",
"state": "approved",
"intent": "sale",
"payer": {...},
"transactions": [{...}],
"links": [{...}] }
Resources and Representations
Manipulate a concept (e.g. payment) with
the intended state
Chaining Actions
The first request builds the action object
Subsequent calls manipulate the object

var paymentObj =
getPreAuth(paymentID)
.getNextAction()
.processNext();

//build pay object
//next HATEOAS link
//process action
In Summation…
Security needs to allow you to work the
browser security model
Always assume statelessness
Build to allow your developers to automate
complexities
Thanks! Questions?
http://www.slideshare.net/jcleblanc

Jonathan LeBlanc (@jcleblanc)
Head of Developer Evangelism
PayPal North America

More Related Content

What's hot (19)

PPTX
REST API Design & Development
Ashok Pundit
 
PPTX
Frisby Api automation
Dineesha Suraweera
 
PPTX
RESTful modules in zf2
Corley S.r.l.
 
PDF
Building Beautiful REST APIs with ASP.NET Core
Stormpath
 
PDF
Securty Testing For RESTful Applications
Source Conference
 
ODP
Attacking REST API
Siddharth Bezalwar
 
PDF
Secure Web Services
Rob Daigneau
 
PDF
Pentesting RESTful webservices
Mohammed A. Imran
 
PDF
Rest api design by george reese
buildacloud
 
PPTX
REST API Design for JAX-RS And Jersey
Stormpath
 
PPTX
Rest API
Rohana K Amarakoon
 
PDF
What is REST API? REST API Concepts and Examples | Edureka
Edureka!
 
PPTX
Designing JavaScript APIs
Jonathan LeBlanc
 
PPTX
Restful webservices
Luqman Shareef
 
PPTX
Understanding REST APIs in 5 Simple Steps
Tessa Mero
 
PDF
Securing REST APIs
Claire Hunsaker
 
PPTX
Elegant Rest Design Webinar
Stormpath
 
ODP
The Internet as Web Services: introduction to ReST
Bruno Kessler Foundation
 
PPTX
Rest API Security
Stormpath
 
REST API Design & Development
Ashok Pundit
 
Frisby Api automation
Dineesha Suraweera
 
RESTful modules in zf2
Corley S.r.l.
 
Building Beautiful REST APIs with ASP.NET Core
Stormpath
 
Securty Testing For RESTful Applications
Source Conference
 
Attacking REST API
Siddharth Bezalwar
 
Secure Web Services
Rob Daigneau
 
Pentesting RESTful webservices
Mohammed A. Imran
 
Rest api design by george reese
buildacloud
 
REST API Design for JAX-RS And Jersey
Stormpath
 
What is REST API? REST API Concepts and Examples | Edureka
Edureka!
 
Designing JavaScript APIs
Jonathan LeBlanc
 
Restful webservices
Luqman Shareef
 
Understanding REST APIs in 5 Simple Steps
Tessa Mero
 
Securing REST APIs
Claire Hunsaker
 
Elegant Rest Design Webinar
Stormpath
 
The Internet as Web Services: introduction to ReST
Bruno Kessler Foundation
 
Rest API Security
Stormpath
 

Viewers also liked (20)

PPTX
Frisby: Rest API Automation Framework
Quovantis
 
PPTX
SeaJUG May 2012 mybatis
Will Iverson
 
PPTX
How to Choose an API Automation Tool for a Distributed Cloud-based App: To...
Altoros
 
PPTX
Design Summit - RESTful API Overview - John Hardy
ManageIQ
 
PDF
OpenERP 6.1 Framework Changes
Odoo
 
PDF
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Vladimir Bacvanski, PhD
 
PDF
Светлана Исакова «Язык Kotlin»
e-Legion
 
PDF
MyBatis 개요와 Java+MyBatis+MySQL 예제
정완 전
 
PPTX
SpringBoot with MyBatis, Flyway, QueryDSL
Sunghyouk Bae
 
PPTX
MyBatis
Roman Dovgan
 
PDF
Kotlin in action
Ciro Rizzo
 
PDF
A brief introduction to Realm with Kotlin
Leonardo YongUk Kim
 
PDF
API TEST
copremesis
 
PDF
Web API Test Automation using Frisby & Node.js
Chi Lang Le Vu Tran
 
PPTX
API Management Platform Technical Evaluation Framework
WSO2
 
PPTX
Vitalis 2016 FHIR App Development
Ewout Kramer
 
PPTX
How to Design a Successful Test Automation Strategy
Impetus Technologies
 
PDF
Test Automation Framework Design | www.idexcel.com
Idexcel Technologies
 
PDF
通往測試最高殿堂的旅程 - GTAC 2016
Chloe Chen
 
PDF
Introduction to Test Automation - Technology and Tools
KMS Technology
 
Frisby: Rest API Automation Framework
Quovantis
 
SeaJUG May 2012 mybatis
Will Iverson
 
How to Choose an API Automation Tool for a Distributed Cloud-based App: To...
Altoros
 
Design Summit - RESTful API Overview - John Hardy
ManageIQ
 
OpenERP 6.1 Framework Changes
Odoo
 
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Vladimir Bacvanski, PhD
 
Светлана Исакова «Язык Kotlin»
e-Legion
 
MyBatis 개요와 Java+MyBatis+MySQL 예제
정완 전
 
SpringBoot with MyBatis, Flyway, QueryDSL
Sunghyouk Bae
 
MyBatis
Roman Dovgan
 
Kotlin in action
Ciro Rizzo
 
A brief introduction to Realm with Kotlin
Leonardo YongUk Kim
 
API TEST
copremesis
 
Web API Test Automation using Frisby & Node.js
Chi Lang Le Vu Tran
 
API Management Platform Technical Evaluation Framework
WSO2
 
Vitalis 2016 FHIR App Development
Ewout Kramer
 
How to Design a Successful Test Automation Strategy
Impetus Technologies
 
Test Automation Framework Design | www.idexcel.com
Idexcel Technologies
 
通往測試最高殿堂的旅程 - GTAC 2016
Chloe Chen
 
Introduction to Test Automation - Technology and Tools
KMS Technology
 
Ad

Similar to Secure RESTful API Automation With JavaScript (20)

PPTX
Securing RESTful APIs using OAuth 2 and OpenID Connect
Jonathan LeBlanc
 
PPTX
Securing RESTful Payment APIs Using OAuth 2
Jonathan LeBlanc
 
PPTX
API design principles for accelerated development
Jonathan LeBlanc
 
PPT
Securing RESTful API
Muhammad Zbeedat
 
PPTX
(1) OAuth 2.0 Overview
anikristo
 
PPTX
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Nilanjan Roy
 
PDF
oauth-for-credentials-security-in-rest-api-access
idsecconf
 
PPTX
OAuth2 + API Security
Amila Paranawithana
 
PDF
Full stack security
DPC Consulting Ltd
 
PPTX
OAuth2 and OpenID with Spring Boot
Geert Pante
 
PDF
OAuth2
SPARK MEDIA
 
PPTX
OAuth2 Implementation Presentation (Java)
Knoldus Inc.
 
PPTX
Restful api
Anurag Srivastava
 
PDF
OAuth 2.0 for Web and Native (Mobile) App Developers
Prabath Siriwardena
 
PDF
Securing APIs with OAuth 2.0
Kai Hofstetter
 
PPTX
Best Practices in Building an API Security Ecosystem
Prabath Siriwardena
 
PDF
Spring security oauth2
axykim00
 
PPTX
Securing API data models
Jonathan LeBlanc
 
PPTX
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
 
PPTX
Devteach 2017 OAuth and Open id connect demystified
Taswar Bhatti
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Jonathan LeBlanc
 
Securing RESTful Payment APIs Using OAuth 2
Jonathan LeBlanc
 
API design principles for accelerated development
Jonathan LeBlanc
 
Securing RESTful API
Muhammad Zbeedat
 
(1) OAuth 2.0 Overview
anikristo
 
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Nilanjan Roy
 
oauth-for-credentials-security-in-rest-api-access
idsecconf
 
OAuth2 + API Security
Amila Paranawithana
 
Full stack security
DPC Consulting Ltd
 
OAuth2 and OpenID with Spring Boot
Geert Pante
 
OAuth2
SPARK MEDIA
 
OAuth2 Implementation Presentation (Java)
Knoldus Inc.
 
Restful api
Anurag Srivastava
 
OAuth 2.0 for Web and Native (Mobile) App Developers
Prabath Siriwardena
 
Securing APIs with OAuth 2.0
Kai Hofstetter
 
Best Practices in Building an API Security Ecosystem
Prabath Siriwardena
 
Spring security oauth2
axykim00
 
Securing API data models
Jonathan LeBlanc
 
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
 
Devteach 2017 OAuth and Open id connect demystified
Taswar Bhatti
 
Ad

More from Jonathan LeBlanc (20)

PDF
JavaScript App Security: Auth and Identity on the Client
Jonathan LeBlanc
 
PDF
Improving Developer Onboarding Through Intelligent Data Insights
Jonathan LeBlanc
 
PDF
Better Data with Machine Learning and Serverless
Jonathan LeBlanc
 
PPTX
Best Practices for Application Development with Box
Jonathan LeBlanc
 
PPTX
Box Platform Overview
Jonathan LeBlanc
 
PPTX
Box Platform Developer Workshop
Jonathan LeBlanc
 
PPTX
Modern Cloud Data Security Practices
Jonathan LeBlanc
 
PPTX
Box Authentication Types
Jonathan LeBlanc
 
PPTX
Understanding Box UI Elements
Jonathan LeBlanc
 
PPTX
Understanding Box applications, tokens, and scoping
Jonathan LeBlanc
 
PPTX
The Future of Online Money: Creating Secure Payments Globally
Jonathan LeBlanc
 
PDF
Modern API Security with JSON Web Tokens
Jonathan LeBlanc
 
PPTX
Creating an In-Aisle Purchasing System from Scratch
Jonathan LeBlanc
 
PDF
Secure Payments Over Mixed Communication Media
Jonathan LeBlanc
 
PDF
Protecting the Future of Mobile Payments
Jonathan LeBlanc
 
PDF
Node.js Authentication and Data Security
Jonathan LeBlanc
 
PDF
PHP Identity and Data Security
Jonathan LeBlanc
 
PPTX
Secure Payments Over Mixed Communication Media
Jonathan LeBlanc
 
PDF
Protecting the Future of Mobile Payments
Jonathan LeBlanc
 
PPTX
Future of Identity, Data, and Wearable Security
Jonathan LeBlanc
 
JavaScript App Security: Auth and Identity on the Client
Jonathan LeBlanc
 
Improving Developer Onboarding Through Intelligent Data Insights
Jonathan LeBlanc
 
Better Data with Machine Learning and Serverless
Jonathan LeBlanc
 
Best Practices for Application Development with Box
Jonathan LeBlanc
 
Box Platform Overview
Jonathan LeBlanc
 
Box Platform Developer Workshop
Jonathan LeBlanc
 
Modern Cloud Data Security Practices
Jonathan LeBlanc
 
Box Authentication Types
Jonathan LeBlanc
 
Understanding Box UI Elements
Jonathan LeBlanc
 
Understanding Box applications, tokens, and scoping
Jonathan LeBlanc
 
The Future of Online Money: Creating Secure Payments Globally
Jonathan LeBlanc
 
Modern API Security with JSON Web Tokens
Jonathan LeBlanc
 
Creating an In-Aisle Purchasing System from Scratch
Jonathan LeBlanc
 
Secure Payments Over Mixed Communication Media
Jonathan LeBlanc
 
Protecting the Future of Mobile Payments
Jonathan LeBlanc
 
Node.js Authentication and Data Security
Jonathan LeBlanc
 
PHP Identity and Data Security
Jonathan LeBlanc
 
Secure Payments Over Mixed Communication Media
Jonathan LeBlanc
 
Protecting the Future of Mobile Payments
Jonathan LeBlanc
 
Future of Identity, Data, and Wearable Security
Jonathan LeBlanc
 

Recently uploaded (20)

PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
DOCX
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
PDF
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PDF
Python Conference Singapore - 19 Jun 2025
ninefyi
 
PDF
The Growing Value and Application of FME & GenAI
Safe Software
 
PDF
Kubernetes - Architecture & Components.pdf
geethak285
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PPTX
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
FME as an Orchestration Tool with Principles From Data Gravity
Safe Software
 
Plugging AI into everything: Model Context Protocol Simplified.pdf
Abati Adewale
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
Python Conference Singapore - 19 Jun 2025
ninefyi
 
The Growing Value and Application of FME & GenAI
Safe Software
 
Kubernetes - Architecture & Components.pdf
geethak285
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 

Secure RESTful API Automation With JavaScript

Editor's Notes

  • #7: Keeping private keys private
  • #23: JSONP can cause XSS issues where the external site is compromised, CORS allows websites to manually parse responses to ensure security
  • #26: Behind the server scene, the server looks up the application in their records to verify that the application matches what is on file against the application location making the request
  • #30: Hypermedia as the engine of application state
  • #35: Resources must be manipulated via representations. This goes back to the stateless principles
  • #38: REST principle of using objects applied to chaining multiple objects together