SlideShare a Scribd company logo
Securing RESTful APIs
Using OAuth 2 and OpenID Connect
Jonathan LeBlanc (@jcleblanc)
Head of Developer Evangelism
PayPal North America
What We’re Covering
Auth History and REST Concepts
Adding in an Auth Mechanism
Integration in Practice
(server + client side integrations)
What We Want
The Ultimate Decision
Security Usability
Path to the Standard
The Insecure, Unmanageable Start
Very Secure, Long to Implement
Two Currently Widely Used Specs
REST Architecture
What a RESTful API isn’t
Our API is RESTful, we support GET,
PUT, POST, and DELETE requests
No…actually you just support
HTTP…like the rest of the web.
What a RESTful API is
Honor HTTP request verbs
Use proper HTTP status codes
No version numbering in URIs
Return format via HTTP Accept header
Does Anyone Actually Do That?
Very few APIs
follow pragmatic
REST principles
HATEOAS
"links": [{
"href": "https://api.sandbox.paypal.com/v1/payments/
payment/PAY-6RV75EKEYSZ6Y",
"rel": "self",
"method": "GET"
},{
"href": "https://www.sandbox.paypal.com/webscr?
cmd=_express-checkout&token=EC-6019609",
"rel": "approval_url",
"method": "REDIRECT"
},{
"href": "https://api.sandbox.paypal.com/v1/payments/
payment/PAY-6RV75EKEYSZ6Y/execute",
"rel": "execute",
"method": "POST"
}
]
Adding Auth Mechanisms
Reasons for Auth
Rate Limiting and Attack Vector Protection
Having the ability to revoke application
access
Needing to allow users to revoke an
applications access to their data
When You Need Access Security
A Few Different Flavors of Usage
User login (authentication)
Application only (bearer tokens)
User Involvement (authorization)
Practical Implementation
Fetching the Access Token
Fetch the Access Token
Access Token Endpoint
client_id grant_type
client_secret
HTTP POST
Access Token Endpoint
Fetching the Access Token
curl https://api.sandbox.paypal.com/v1/oauth2/token 
-H "Accept: application/json" 
-H "Accept-Language: en_US" 
-u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFd…" 
-d "grant_type=client_credentials"
Access Token Response
{
"scope": "https://api.paypal.com/v1/payments/.*
https://api.paypal.com/v1/vault/credit-card",
"access_token": "EEwJ6tF9x5WCIZDYzyZGaz6K…",
"token_type": "Bearer",
"app_id": "APP-6XR95014SS315863X",
"expires_in": 28800
}
Using the Access Token
Fetch Privileged Resources
Resource Endpoint
Token Type (Authorization header)
Access Token (Authorization header)
HTTP GET / PUT / POST /
DELETE
Resource Endpoint
Using the Access Token
curl -v
https://api.sandbox.paypal.com/v1/payments/payment 
-H "Content-Type:application/json" 
-H "Authorization:Bearer EMxItHE7Zl4cMdkv…" 
-d "{...}"
A few implementation differences
Endpoints
Scopes (dynamic / static)
Using the Access Token in a request
OAuth 2 & JavaScript?
The Complexities of JavaScript
The same-origin policy
Keeping private keys private
Not having to provide a hacked
experience
The Ways we Made it Work
Server-side proxy
Flash / iframe proxy
Private token storage
mechanism
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
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+)/);
Extracting the access token from the hash
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
$.ajax({
url: resource_uri,
beforeSend: function (xhr) {
xhr.setRequestHeader('Authorization', 'OAuth ' + token);
xhr.setRequestHeader('Accept', 'application/json');
},
success: function (response) {
//use response object
}
});
Making an authorized request
Using the Skeleton Key
How it’s Normally Used
Access user details
Push data through
user social streams
But why?
Access token as a
control structure
Improve Existing
Products
Our showcase:
Seamless Checkout
The Last Considerations
REST and OAuth are specifications,
not religions
Don’t alienate your developers
with security
Open source is your friend
A Few Code Links
OAuth2 & OpenID Connect Samples
https://github.com/jcleblanc/oauth
https://github.com/paypal/paypal-access
Log in with PayPal
http://bit.ly/loginwithpaypal
Thank You! Questions?
http://slideshare.net/jcleblanc
Jonathan LeBlanc (@jcleblanc)
Head of Developer Evangelism
PayPal North America

More Related Content

PPTX
Single-Page-Application & REST security
PDF
OAuth - Open API Authentication
PPTX
An Introduction to OAuth2
PDF
OAuth 2.0
PPTX
REST Service Authetication with TLS & JWTs
PDF
Modern Security with OAuth 2.0 and JWT and Spring by Dmitry Buzdin
PDF
Stateless authentication for microservices - GR8Conf 2015
PDF
Stateless Auth using OAuth2 & JWT
Single-Page-Application & REST security
OAuth - Open API Authentication
An Introduction to OAuth2
OAuth 2.0
REST Service Authetication with TLS & JWTs
Modern Security with OAuth 2.0 and JWT and Spring by Dmitry Buzdin
Stateless authentication for microservices - GR8Conf 2015
Stateless Auth using OAuth2 & JWT

What's hot (20)

PDF
Demystifying OAuth 2.0
PPTX
Rest API Security
ODP
OAuth2 - Introduction
PDF
OAuth2 and Spring Security
PPTX
OAuth2 + API Security
PPTX
Best Practices in Building an API Security Ecosystem
PPTX
JWT Authentication with AngularJS
PDF
ConFoo 2015 - Securing RESTful resources with OAuth2
PDF
The Ultimate Guide to Mobile API Security
PPTX
Securing RESTful Payment APIs Using OAuth 2
PPTX
Oauth2 and OWSM OAuth2 support
PPTX
Securing your APIs with OAuth, OpenID, and OpenID Connect
PPTX
Oauth 2.0 security
PDF
Implementing OAuth
PPTX
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
PDF
OAuth2 Authentication
ODP
Mohanraj - Securing Your Web Api With OAuth
PDF
JavaOne 2014 - Securing RESTful Resources with OAuth2
PPTX
An Introduction to OAuth 2
PPTX
An introduction to OAuth 2
Demystifying OAuth 2.0
Rest API Security
OAuth2 - Introduction
OAuth2 and Spring Security
OAuth2 + API Security
Best Practices in Building an API Security Ecosystem
JWT Authentication with AngularJS
ConFoo 2015 - Securing RESTful resources with OAuth2
The Ultimate Guide to Mobile API Security
Securing RESTful Payment APIs Using OAuth 2
Oauth2 and OWSM OAuth2 support
Securing your APIs with OAuth, OpenID, and OpenID Connect
Oauth 2.0 security
Implementing OAuth
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
OAuth2 Authentication
Mohanraj - Securing Your Web Api With OAuth
JavaOne 2014 - Securing RESTful Resources with OAuth2
An Introduction to OAuth 2
An introduction to OAuth 2
Ad

Viewers also liked (7)

PDF
OpenID Connect Explained
PDF
OpenID Authentication by example
PDF
Introduction to OpenID Connect
PPTX
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
PDF
OAuth 2.0 & OpenID Connect @ OpenSource Conference 2011 Tokyo #osc11tk
PPTX
OpenID Connect and Single Sign-On for Beginners
PPTX
OpenID Connect - a simple[sic] single sign-on & identity layer on top of OAut...
OpenID Connect Explained
OpenID Authentication by example
Introduction to OpenID Connect
Best Practices You Must Apply to Secure Your APIs - Scott Morrison, SVP & Dis...
OAuth 2.0 & OpenID Connect @ OpenSource Conference 2011 Tokyo #osc11tk
OpenID Connect and Single Sign-On for Beginners
OpenID Connect - a simple[sic] single sign-on & identity layer on top of OAut...
Ad

Similar to Securing RESTful APIs using OAuth 2 and OpenID Connect (20)

PPTX
Designing JavaScript APIs
PPTX
Secure RESTful API Automation With JavaScript
PPT
UserCentric Identity based Service Invocation
PDF
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
PDF
What the Heck is OAuth and OIDC - UberConf 2018
PDF
Security enforcement of Java Microservices with Apiman & Keycloak
PDF
iMasters Intercon 2016 - Identity within Microservices
PDF
InterCon 2016 - Segurança de identidade digital levando em consideração uma a...
PDF
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
PPTX
API design principles for accelerated development
PDF
REST APIs in the context of single-page applications
PPTX
Rest API Security - A quick understanding of Rest API Security
PPTX
Restful api
PDF
Keeping Pace with OAuth’s Evolving Security Practices.pdf
PPTX
How to Use Stormpath in angular js
PPTX
Best Practices for Architecting a Pragmatic Web API.
PPTX
Externalizing Authorization in Micro Services world
PDF
WebApp #3 : API
PPTX
REST API Security: OAuth 2.0, JWTs, and More!
PPT
Pentesting web applications
Designing JavaScript APIs
Secure RESTful API Automation With JavaScript
UserCentric Identity based Service Invocation
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
What the Heck is OAuth and OIDC - UberConf 2018
Security enforcement of Java Microservices with Apiman & Keycloak
iMasters Intercon 2016 - Identity within Microservices
InterCon 2016 - Segurança de identidade digital levando em consideração uma a...
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
API design principles for accelerated development
REST APIs in the context of single-page applications
Rest API Security - A quick understanding of Rest API Security
Restful api
Keeping Pace with OAuth’s Evolving Security Practices.pdf
How to Use Stormpath in angular js
Best Practices for Architecting a Pragmatic Web API.
Externalizing Authorization in Micro Services world
WebApp #3 : API
REST API Security: OAuth 2.0, JWTs, and More!
Pentesting web applications

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
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Electronic commerce courselecture one. Pdf
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
KodekX | Application Modernization Development
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Machine learning based COVID-19 study performance prediction
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPT
Teaching material agriculture food technology
PDF
Modernizing your data center with Dell and AMD
PPTX
Cloud computing and distributed systems.
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Electronic commerce courselecture one. Pdf
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
KodekX | Application Modernization Development
Understanding_Digital_Forensics_Presentation.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Encapsulation_ Review paper, used for researhc scholars
The AUB Centre for AI in Media Proposal.docx
Dropbox Q2 2025 Financial Results & Investor Presentation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
The Rise and Fall of 3GPP – Time for a Sabbatical?
Per capita expenditure prediction using model stacking based on satellite ima...
Machine learning based COVID-19 study performance prediction
NewMind AI Weekly Chronicles - August'25 Week I
Teaching material agriculture food technology
Modernizing your data center with Dell and AMD
Cloud computing and distributed systems.

Securing RESTful APIs using OAuth 2 and OpenID Connect

  • 1. Securing RESTful APIs Using OAuth 2 and OpenID Connect Jonathan LeBlanc (@jcleblanc) Head of Developer Evangelism PayPal North America
  • 2. What We’re Covering Auth History and REST Concepts Adding in an Auth Mechanism Integration in Practice (server + client side integrations)
  • 5. Path to the Standard
  • 7. Very Secure, Long to Implement
  • 8. Two Currently Widely Used Specs
  • 10. What a RESTful API isn’t Our API is RESTful, we support GET, PUT, POST, and DELETE requests No…actually you just support HTTP…like the rest of the web.
  • 11. What a RESTful API is Honor HTTP request verbs Use proper HTTP status codes No version numbering in URIs Return format via HTTP Accept header
  • 12. Does Anyone Actually Do That? Very few APIs follow pragmatic REST principles
  • 14. "links": [{ "href": "https://api.sandbox.paypal.com/v1/payments/ payment/PAY-6RV75EKEYSZ6Y", "rel": "self", "method": "GET" },{ "href": "https://www.sandbox.paypal.com/webscr? cmd=_express-checkout&token=EC-6019609", "rel": "approval_url", "method": "REDIRECT" },{ "href": "https://api.sandbox.paypal.com/v1/payments/ payment/PAY-6RV75EKEYSZ6Y/execute", "rel": "execute", "method": "POST" } ]
  • 16. Reasons for Auth Rate Limiting and Attack Vector Protection Having the ability to revoke application access Needing to allow users to revoke an applications access to their data
  • 17. When You Need Access Security
  • 18. A Few Different Flavors of Usage User login (authentication) Application only (bearer tokens) User Involvement (authorization)
  • 20. Fetching the Access Token Fetch the Access Token Access Token Endpoint client_id grant_type client_secret HTTP POST Access Token Endpoint
  • 21. Fetching the Access Token curl https://api.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFd…" -d "grant_type=client_credentials"
  • 22. Access Token Response { "scope": "https://api.paypal.com/v1/payments/.* https://api.paypal.com/v1/vault/credit-card", "access_token": "EEwJ6tF9x5WCIZDYzyZGaz6K…", "token_type": "Bearer", "app_id": "APP-6XR95014SS315863X", "expires_in": 28800 }
  • 23. Using the Access Token Fetch Privileged Resources Resource Endpoint Token Type (Authorization header) Access Token (Authorization header) HTTP GET / PUT / POST / DELETE Resource Endpoint
  • 24. Using the Access Token curl -v https://api.sandbox.paypal.com/v1/payments/payment -H "Content-Type:application/json" -H "Authorization:Bearer EMxItHE7Zl4cMdkv…" -d "{...}"
  • 25. A few implementation differences Endpoints Scopes (dynamic / static) Using the Access Token in a request
  • 26. OAuth 2 & JavaScript?
  • 27. The Complexities of JavaScript The same-origin policy Keeping private keys private Not having to provide a hacked experience
  • 28. The Ways we Made it Work Server-side proxy Flash / iframe proxy Private token storage mechanism
  • 29. User Agent Flow: Redirect Prepare the Redirect URI Authorization Endpoint client_id response_type (token) scope redirect_uri Browser Redirect Redirect URI
  • 30. 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);
  • 31. User Agent Flow: Hash Mod Fetch the Hash Mod access_token refresh_token expires_in Extract Access Token
  • 32. User Agent Flow: Hash Mod 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+)/); Extracting the access token from the hash
  • 33. User Agent Flow: Get Resources Set Request Headers + URI Resource Endpoint Header: token type + access token Header: accept data type HTTPS Request
  • 34. User Agent Flow: Get Resources $.ajax({ url: resource_uri, beforeSend: function (xhr) { xhr.setRequestHeader('Authorization', 'OAuth ' + token); xhr.setRequestHeader('Accept', 'application/json'); }, success: function (response) { //use response object } }); Making an authorized request
  • 36. How it’s Normally Used Access user details Push data through user social streams
  • 37. But why? Access token as a control structure Improve Existing Products Our showcase: Seamless Checkout
  • 38. The Last Considerations REST and OAuth are specifications, not religions Don’t alienate your developers with security Open source is your friend
  • 39. A Few Code Links OAuth2 & OpenID Connect Samples https://github.com/jcleblanc/oauth https://github.com/paypal/paypal-access Log in with PayPal http://bit.ly/loginwithpaypal
  • 40. Thank You! Questions? http://slideshare.net/jcleblanc Jonathan LeBlanc (@jcleblanc) Head of Developer Evangelism PayPal North America

Editor's Notes

  • #4: What we want
  • #15: Working with HATEOASHypermedia as the Engine of Application State("hate -o's") or "hate yo' ass"