SlideShare a Scribd company logo
1 of 21
Download to read offline
OAuth2 Best Practices in Native Apps
Jeff Fontas
Partner Engineer
linkedin.com/in/fontasj
Welcome to LinkedIn
Partner Engineering
@ LinkedIn
• Enable integrations
• Amazing coworkers and partners
• Values-driven culture
• Interested? Talk to me
Agenda
• A few words about OAuth2
• Native apps and what makes them different
• Best practices and a demo implementing
them
OAuth2
What is OAuth2?
User
App
Resource
Getting Consent
Some More About the Redirect
GET /oauth?code=<auth code> HTTP/1.1
Host: www.jeffstestapp.com
Request from redirected browser
POST /oauth/v2/accessToken HTTP/1.1
Host: www.linkedin.com
Content-Type:
application/x-www-form-urlencoded
grant_type=authorization_code&
code=<auth code>&
client_id=<app client id>&
client_secret=<client secret>&
redirect_uri=<redirect uri>
Jeff’s Test App exchanges auth
code for access token
Make Requests
GET /me HTTP/1.1
Host: api.linkedin.com
Authorization: Bearer <Access Token>
GET request made by Jeff’s Test App to
LinkedIn for profile data
Native Apps
Defining Native Apps
• Mobile apps (iOS, Android)
• Desktop apps (including Electron,
NW.js)
What makes OAuth2 in native apps different?
• Physically on device
• Embedded browsers
• May be updated less frequently
Some Best Practices
Best Practice 1: Use the System Browser
• Usability
• Security
Best Practice 2: Getting Context from the System Browser
• Use the redirect
• Custom protocol handler
• Listen locally
Example Redirect URIs
Custom protocol handler:
linkedIn://oauth?code=<auth code>
Listen locally:
http://localhost:1234?code=<auth code>
Best Practice 3: Use PKCE
• Alternative to secrets
• Randomly generated code
• Since secrets are out, no refresh tokens
Demo
• Native desktop app (Qt/PyQt)
• Opens system browser
• Spawns Node, listens on port
1234
• Node performs auth code
exchange for access token
Jeff’s Test App
Node Server
Listens Locally
Returns
token
Redirect with Auth
Code
Code
const requestHandler = (req, response) => {
let queryString = qs.parse(url.parse(req.url).query)
if (queryString.code) {
let authCode = queryString.code
let oauth2Url = 'https://www.linkedin.com/oauth/v2/accessToken'
let form = {
"grant_type": "authorization_code",
"code" : authCode,
"client_id": config.app.key,
"code_verifier": generated_code,
"redirect_uri": "http://localhost:1234"
}
request.post({url:oauth2Url, form:form}, (err, httpResponse, body) => {
if (err) {
console.log(err)
}
console.log(JSON.parse(body).access_token)
process.exit(0)
})
}
response.end('Received auth code.')
}
const server = http.createServer(requestHandler)
Lessons Learned
• Don’t spawn a child process
• Use whatever tools are at your disposal in your native
application (leverage Node in Electron, NW.js, for example)
Further Reading
• RFC 8252 -- OAuth 2.0 for Native Apps
https://tools.ietf.org/html/rfc8252
• RFC 7636 -- Proof Key for Code Exchange
https://tools.ietf.org/html/rfc7636
Thank you

More Related Content

What's hot

Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
Igor Bossenko
 
Mohanraj - Securing Your Web Api With OAuth
Mohanraj - Securing Your Web Api With OAuthMohanraj - Securing Your Web Api With OAuth
Mohanraj - Securing Your Web Api With OAuth
fossmy
 

What's hot (20)

Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2Securing RESTful Payment APIs Using OAuth 2
Securing RESTful Payment APIs Using OAuth 2
 
Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
 
OpenID vs OAuth - Identity on the Web
OpenID vs OAuth - Identity on the WebOpenID vs OAuth - Identity on the Web
OpenID vs OAuth - Identity on the Web
 
Secure Your REST API (The Right Way)
Secure Your REST API (The Right Way)Secure Your REST API (The Right Way)
Secure Your REST API (The Right Way)
 
Mohanraj - Securing Your Web Api With OAuth
Mohanraj - Securing Your Web Api With OAuthMohanraj - Securing Your Web Api With OAuth
Mohanraj - Securing Your Web Api With OAuth
 
Rest API Security
Rest API SecurityRest API Security
Rest API Security
 
REST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTsREST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTs
 
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
API Security & Federation Patterns - Francois Lascelles, Chief Architect, Lay...
 
Secure API Services in Node with Basic Auth and OAuth2
Secure API Services in Node with Basic Auth and OAuth2Secure API Services in Node with Basic Auth and OAuth2
Secure API Services in Node with Basic Auth and OAuth2
 
Building Apps with MySpace SDKs
Building Apps with MySpace SDKsBuilding Apps with MySpace SDKs
Building Apps with MySpace SDKs
 
Secure RESTful API Automation With JavaScript
Secure RESTful API Automation With JavaScriptSecure RESTful API Automation With JavaScript
Secure RESTful API Automation With JavaScript
 
Securty Testing For RESTful Applications
Securty Testing For RESTful ApplicationsSecurty Testing For RESTful Applications
Securty Testing For RESTful Applications
 
Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015
 
Presentation
PresentationPresentation
Presentation
 
Building Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET CoreBuilding Beautiful REST APIs with ASP.NET Core
Building Beautiful REST APIs with ASP.NET Core
 
Token Authentication for Java Applications
Token Authentication for Java ApplicationsToken Authentication for Java Applications
Token Authentication for Java Applications
 
Building an API Security Ecosystem
Building an API Security EcosystemBuilding an API Security Ecosystem
Building an API Security Ecosystem
 
OAuth Tokens
OAuth TokensOAuth Tokens
OAuth Tokens
 
Api security
Api security Api security
Api security
 
RESTful API Automation with JavaScript
RESTful API Automation with JavaScriptRESTful API Automation with JavaScript
RESTful API Automation with JavaScript
 

Similar to OAuth2 Best Practices in Native Apps

Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Aaron Parecki
 

Similar to OAuth2 Best Practices in Native Apps (20)

Securing .NET Core, ASP.NET Core applications
Securing .NET Core, ASP.NET Core applicationsSecuring .NET Core, ASP.NET Core applications
Securing .NET Core, ASP.NET Core applications
 
Application Security in ASP.NET Core
Application Security in ASP.NET CoreApplication Security in ASP.NET Core
Application Security in ASP.NET Core
 
OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and Library
 
How to build Simple yet powerful API.pptx
How to build Simple yet powerful API.pptxHow to build Simple yet powerful API.pptx
How to build Simple yet powerful API.pptx
 
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
 
OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring Boot
 
OAuth and OEmbed
OAuth and OEmbedOAuth and OEmbed
OAuth and OEmbed
 
Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares
 
Mobile Authentication - Onboarding, best practices & anti-patterns
Mobile Authentication - Onboarding, best practices & anti-patternsMobile Authentication - Onboarding, best practices & anti-patterns
Mobile Authentication - Onboarding, best practices & anti-patterns
 
CIS 2012 - Going Mobile with PingFederate and OAuth 2
CIS 2012 - Going Mobile with PingFederate and OAuth 2CIS 2012 - Going Mobile with PingFederate and OAuth 2
CIS 2012 - Going Mobile with PingFederate and OAuth 2
 
ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2
 
Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0
 
Adding Identity Management and Access Control to your App
Adding Identity Management and Access Control to your AppAdding Identity Management and Access Control to your App
Adding Identity Management and Access Control to your App
 
How to Build an Indivo X Personal Health App
How to Build an Indivo X Personal Health AppHow to Build an Indivo X Personal Health App
How to Build an Indivo X Personal Health App
 
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
 
Introduction to the Globus Platform for Developers
Introduction to the Globus Platform for DevelopersIntroduction to the Globus Platform for Developers
Introduction to the Globus Platform for Developers
 
What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018
 
Adding identity management and access control to your app
Adding identity management and access control to your appAdding identity management and access control to your app
Adding identity management and access control to your app
 
OAuth2 para desarrolladores
OAuth2 para desarrolladoresOAuth2 para desarrolladores
OAuth2 para desarrolladores
 
Accessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) webAccessing APIs using OAuth on the federated (WordPress) web
Accessing APIs using OAuth on the federated (WordPress) web
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Recently uploaded (20)

Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

OAuth2 Best Practices in Native Apps

  • 1. OAuth2 Best Practices in Native Apps Jeff Fontas Partner Engineer linkedin.com/in/fontasj
  • 3. Partner Engineering @ LinkedIn • Enable integrations • Amazing coworkers and partners • Values-driven culture • Interested? Talk to me
  • 4. Agenda • A few words about OAuth2 • Native apps and what makes them different • Best practices and a demo implementing them
  • 8. Some More About the Redirect GET /oauth?code=<auth code> HTTP/1.1 Host: www.jeffstestapp.com Request from redirected browser POST /oauth/v2/accessToken HTTP/1.1 Host: www.linkedin.com Content-Type: application/x-www-form-urlencoded grant_type=authorization_code& code=<auth code>& client_id=<app client id>& client_secret=<client secret>& redirect_uri=<redirect uri> Jeff’s Test App exchanges auth code for access token
  • 9. Make Requests GET /me HTTP/1.1 Host: api.linkedin.com Authorization: Bearer <Access Token> GET request made by Jeff’s Test App to LinkedIn for profile data
  • 11. Defining Native Apps • Mobile apps (iOS, Android) • Desktop apps (including Electron, NW.js)
  • 12. What makes OAuth2 in native apps different? • Physically on device • Embedded browsers • May be updated less frequently
  • 14. Best Practice 1: Use the System Browser • Usability • Security
  • 15. Best Practice 2: Getting Context from the System Browser • Use the redirect • Custom protocol handler • Listen locally Example Redirect URIs Custom protocol handler: linkedIn://oauth?code=<auth code> Listen locally: http://localhost:1234?code=<auth code>
  • 16. Best Practice 3: Use PKCE • Alternative to secrets • Randomly generated code • Since secrets are out, no refresh tokens
  • 17. Demo • Native desktop app (Qt/PyQt) • Opens system browser • Spawns Node, listens on port 1234 • Node performs auth code exchange for access token Jeff’s Test App Node Server Listens Locally Returns token Redirect with Auth Code
  • 18. Code const requestHandler = (req, response) => { let queryString = qs.parse(url.parse(req.url).query) if (queryString.code) { let authCode = queryString.code let oauth2Url = 'https://www.linkedin.com/oauth/v2/accessToken' let form = { "grant_type": "authorization_code", "code" : authCode, "client_id": config.app.key, "code_verifier": generated_code, "redirect_uri": "http://localhost:1234" } request.post({url:oauth2Url, form:form}, (err, httpResponse, body) => { if (err) { console.log(err) } console.log(JSON.parse(body).access_token) process.exit(0) }) } response.end('Received auth code.') } const server = http.createServer(requestHandler)
  • 19. Lessons Learned • Don’t spawn a child process • Use whatever tools are at your disposal in your native application (leverage Node in Electron, NW.js, for example)
  • 20. Further Reading • RFC 8252 -- OAuth 2.0 for Native Apps https://tools.ietf.org/html/rfc8252 • RFC 7636 -- Proof Key for Code Exchange https://tools.ietf.org/html/rfc7636