Secure API Services in Node with Basic Auth and OAuth2

23
Secure API Services in Node.js

Transcript of Secure API Services in Node with Basic Auth and OAuth2

Page 1: Secure API Services in Node with Basic Auth and OAuth2

Secure API Services in Node.js

Page 2: Secure API Services in Node with Basic Auth and OAuth2

Welcome! • Agenda

• Stormpath 101 (5 mins)• How to secure an API (25 mins)• Q&A (30 mins)

• Claire HunsakerVP of Marketing & Customer Success

• Randall DeggesNode.js Evangelist

Page 3: Secure API Services in Node with Basic Auth and OAuth2

Customer Identity Poses Major Challenges

Page 4: Secure API Services in Node with Basic Auth and OAuth2

Speed to Market & Cost Reduction• Complete Identity solution out-of-the-box• Security best practices and updates by

default• Clean & elegant API/SDKs• Little to code, no maintenance Focus on Your Core Competency

Page 5: Secure API Services in Node with Basic Auth and OAuth2

Stormpath User Management

User Data

User Workflows Google ID

Your Applications

Application SDK

Application SDK

Application SDK

ID Integrations

Facebook

Active Directory

SAML

Page 6: Secure API Services in Node with Basic Auth and OAuth2

Features• Secure, flexible Authentication

(Password, Token, OAuth, API)

• Deep AuthorizationGroups, RolesCustomer OrganizationsPermissions

• Customer Profile Data

• Single Sign-On Across Your Apps

• Hosted User Screens

Page 7: Secure API Services in Node with Basic Auth and OAuth2

What’s the Goal of This Talk?

Page 8: Secure API Services in Node with Basic Auth and OAuth2

D’oh!

API Server(s)API Client

API Client

API Client

API Client

Internet

Page 9: Secure API Services in Node with Basic Auth and OAuth2

API Server(s)API Server(s)

Browser / Mobile Web API Client

Client-to-API

Server-to-API

Page 10: Secure API Services in Node with Basic Auth and OAuth2

Basic Auth

OAuth2

What’s the Goal of This Talk?

Page 11: Secure API Services in Node with Basic Auth and OAuth2

About API Keys…

Page 12: Secure API Services in Node with Basic Auth and OAuth2

[email protected]

iLOVEc00kies!

API Server(s)Website

Page 13: Secure API Services in Node with Basic Auth and OAuth2

163e087c36c34fa4b4635995c29cf9b5:b6e7bd4c74cf430493fe03b2e30225f8

API Secret

Long, random strings (uuids).

Page 14: Secure API Services in Node with Basic Auth and OAuth2

Let Users Have Multiple API Keys

Key 1 Key 2

ID: 3c511ea2ef424dd88bc1575e7e5a2bd7Secret: 1ae8120c1ec940638913f4e258b8f7fe

ID: cc463f7aabfd4132a2211006886d05f1Secret: 85172ea5aef144038f019b3111b5e11a

Page 15: Secure API Services in Node with Basic Auth and OAuth2

Creating API Keys with Stormpathreq.user.createApiKey(function(err, apiKey) { if (err) throw err;

 console.log('New API key created!'); console.log('API Key ID:', apiKey.id); console.log('API Key Secret:', apiKey.secret);});

Page 16: Secure API Services in Node with Basic Auth and OAuth2

LET’S SET UP STORMPATH!

Page 17: Secure API Services in Node with Basic Auth and OAuth2

LET’S WRITE SOME CODE!

Page 18: Secure API Services in Node with Basic Auth and OAuth2

How Does Basic Auth Work?

API Server(s)

Authorization: Basic <base64(id:secret)>

$ curl --user id:secret http://localhost:3000/api/test

Page 19: Secure API Services in Node with Basic Auth and OAuth2

How Does OAuth2 Work? (Step 1)

API Server(s)

Authorization: Basic <base64(id:secret)>

Access Token

$ curl --user id:secret \ -X POST \ --data grant_type=client_credentials \ http://localhost:3000/oauth/token

Page 20: Secure API Services in Node with Basic Auth and OAuth2

How Does OAuth2 Work? (Step 2)

API Server(s)

Authorization: Bearer <token>

$ curl -H “Authorization: Bearer <token>” \ http://localhost:3000/api/test

Page 22: Secure API Services in Node with Basic Auth and OAuth2

QUESTIONS?

Page 23: Secure API Services in Node with Basic Auth and OAuth2

THANK YOU