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

PPTX
RESTful API Automation with JavaScript
PDF
Building an API Security Ecosystem
PPTX
Secure Your REST API (The Right Way)
PDF
Understanding and testing restful web services
PDF
The never-ending REST API design debate
PDF
Best Practices in Web Service Design
PDF
Testing REST Web Services
ODP
Mohanraj - Securing Your Web Api With OAuth
RESTful API Automation with JavaScript
Building an API Security Ecosystem
Secure Your REST API (The Right Way)
Understanding and testing restful web services
The never-ending REST API design debate
Best Practices in Web Service Design
Testing REST Web Services
Mohanraj - Securing Your Web Api With OAuth

What's hot (19)

PPTX
REST API Design & Development
PPTX
Frisby Api automation
PPTX
RESTful modules in zf2
PDF
Building Beautiful REST APIs with ASP.NET Core
PDF
Securty Testing For RESTful Applications
ODP
Attacking REST API
PDF
Secure Web Services
PDF
Pentesting RESTful webservices
PDF
Rest api design by george reese
PPTX
REST API Design for JAX-RS And Jersey
PPTX
PDF
What is REST API? REST API Concepts and Examples | Edureka
PPTX
Designing JavaScript APIs
PPTX
Restful webservices
PPTX
Understanding REST APIs in 5 Simple Steps
PDF
Securing REST APIs
PPTX
Elegant Rest Design Webinar
ODP
The Internet as Web Services: introduction to ReST
PPTX
Rest API Security
REST API Design & Development
Frisby Api automation
RESTful modules in zf2
Building Beautiful REST APIs with ASP.NET Core
Securty Testing For RESTful Applications
Attacking REST API
Secure Web Services
Pentesting RESTful webservices
Rest api design by george reese
REST API Design for JAX-RS And Jersey
What is REST API? REST API Concepts and Examples | Edureka
Designing JavaScript APIs
Restful webservices
Understanding REST APIs in 5 Simple Steps
Securing REST APIs
Elegant Rest Design Webinar
The Internet as Web Services: introduction to ReST
Rest API Security
Ad

Viewers also liked (20)

PPTX
Frisby: Rest API Automation Framework
PPTX
SeaJUG May 2012 mybatis
PPTX
How to Choose an API Automation Tool for a Distributed Cloud-based App: To...
PPTX
Design Summit - RESTful API Overview - John Hardy
PDF
OpenERP 6.1 Framework Changes
PDF
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
PDF
Светлана Исакова «Язык Kotlin»
PDF
MyBatis 개요와 Java+MyBatis+MySQL 예제
PPTX
SpringBoot with MyBatis, Flyway, QueryDSL
PPTX
MyBatis
PDF
Kotlin in action
PDF
A brief introduction to Realm with Kotlin
PDF
API TEST
PDF
Web API Test Automation using Frisby & Node.js
PPTX
API Management Platform Technical Evaluation Framework
PPTX
Vitalis 2016 FHIR App Development
PPTX
How to Design a Successful Test Automation Strategy
PDF
Test Automation Framework Design | www.idexcel.com
PDF
通往測試最高殿堂的旅程 - GTAC 2016
PDF
Introduction to Test Automation - Technology and Tools
Frisby: Rest API Automation Framework
SeaJUG May 2012 mybatis
How to Choose an API Automation Tool for a Distributed Cloud-based App: To...
Design Summit - RESTful API Overview - John Hardy
OpenERP 6.1 Framework Changes
Crash Introduction to Modern Java Data Access: Understanding JPA, Hibernate, ...
Светлана Исакова «Язык Kotlin»
MyBatis 개요와 Java+MyBatis+MySQL 예제
SpringBoot with MyBatis, Flyway, QueryDSL
MyBatis
Kotlin in action
A brief introduction to Realm with Kotlin
API TEST
Web API Test Automation using Frisby & Node.js
API Management Platform Technical Evaluation Framework
Vitalis 2016 FHIR App Development
How to Design a Successful Test Automation Strategy
Test Automation Framework Design | www.idexcel.com
通往測試最高殿堂的旅程 - GTAC 2016
Introduction to Test Automation - Technology and Tools
Ad

Similar to Secure RESTful API Automation With JavaScript (20)

PPTX
Securing RESTful APIs using OAuth 2 and OpenID Connect
PPTX
Securing RESTful Payment APIs Using OAuth 2
PPTX
API design principles for accelerated development
PPT
Securing RESTful API
PPTX
(1) OAuth 2.0 Overview
PPTX
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
PDF
oauth-for-credentials-security-in-rest-api-access
PPTX
OAuth2 + API Security
PDF
Full stack security
PPTX
OAuth2 and OpenID with Spring Boot
PDF
OAuth2
PPTX
OAuth2 Implementation Presentation (Java)
PPTX
Restful api
PDF
OAuth 2.0 for Web and Native (Mobile) App Developers
PDF
Securing APIs with OAuth 2.0
PPTX
Best Practices in Building an API Security Ecosystem
PDF
Spring security oauth2
PPTX
Securing API data models
PPTX
Oauth2 and OWSM OAuth2 support
PPTX
Devteach 2017 OAuth and Open id connect demystified
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful Payment APIs Using OAuth 2
API design principles for accelerated development
Securing RESTful API
(1) OAuth 2.0 Overview
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
oauth-for-credentials-security-in-rest-api-access
OAuth2 + API Security
Full stack security
OAuth2 and OpenID with Spring Boot
OAuth2
OAuth2 Implementation Presentation (Java)
Restful api
OAuth 2.0 for Web and Native (Mobile) App Developers
Securing APIs with OAuth 2.0
Best Practices in Building an API Security Ecosystem
Spring security oauth2
Securing API data models
Oauth2 and OWSM OAuth2 support
Devteach 2017 OAuth and Open id connect demystified

More from Jonathan LeBlanc (20)

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

Recently uploaded (20)

PDF
August Patch Tuesday
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
The various Industrial Revolutions .pptx
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles – August ’25 Week III
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PPT
Geologic Time for studying geology for geologist
PDF
A review of recent deep learning applications in wood surface defect identifi...
PDF
Hindi spoken digit analysis for native and non-native speakers
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
observCloud-Native Containerability and monitoring.pptx
PDF
Getting Started with Data Integration: FME Form 101
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
August Patch Tuesday
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
Univ-Connecticut-ChatGPT-Presentaion.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
1 - Historical Antecedents, Social Consideration.pdf
The various Industrial Revolutions .pptx
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles – August ’25 Week III
Enhancing emotion recognition model for a student engagement use case through...
Getting started with AI Agents and Multi-Agent Systems
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Geologic Time for studying geology for geologist
A review of recent deep learning applications in wood surface defect identifi...
Hindi spoken digit analysis for native and non-native speakers
O2C Customer Invoices to Receipt V15A.pptx
observCloud-Native Containerability and monitoring.pptx
Getting Started with Data Integration: FME Form 101
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
WOOl fibre morphology and structure.pdf for textiles
Final SEM Unit 1 for mit wpu at pune .pptx

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