52
OAuth-as-a- service using ASP.NET Web API and Windows Azure Access Control Maarten Balliauw @maartenballiauw #warmcrocconf

OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Embed Size (px)

DESCRIPTION

API’s are the new apps. They can be consumed by everyone using a web browser or a mobile application on their smartphone or tablet. How would you build your API if you want these apps to be a full-fledged front-end to your service without compromising security? In this session, Maarten will explain how to build an API using the ASP.NET Web API framework and how the Windows Azure Access Control service can be used to almost completely outsource all security and OAuth-related tasks.

Citation preview

Page 1: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access ControlMaarten Balliauw@maartenballiauw

#warmcrocconf

Page 2: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Who am I? Maarten Balliauw

Technical Evangelist, JetBrains

AZUG

Focus on web ASP.NET MVC, Windows Azure, SignalR, ... MVP Windows Azure & ASPInsider

http://blog.maartenballiauw.be

@maartenballiauw

Shameless self promotion: Pro NuGet - http://amzn.to/pronuget

Page 3: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Agenda Why would I need an API?

API characteristics

ASP.NET MVC Web API

Windows Azure ACS

Page 4: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Why would I need an API?

Page 5: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Consuming the web 2000-2008: Desktop browser

2008-2012: Mobile browser

2008-2012: iPhone and Android apps

2010-2014: Tablets, tablets, tablets

2014-2016: Your fridge (Internet of Things)

Page 7: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Twitter & FacebookBy show of hands

Page 8: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Make everyone API(as the French say)

Page 9: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Expose services to 3rd parties

Valuable

Flexible

Managed

Supported

Have a plan

Page 10: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Reach More Clients

Page 11: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

You’re not the only one

Source: http://blog.programmableweb.com/2012/04/16/open-apis-have-become-an-essential-piece-to-the-startup-model/

Page 12: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

API Characteristics

Page 13: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

What is an API? Software-to-Software interface

Contract between software and developers Functionalities, constraints (technical / legal) Programming

instructions and standards

Open services to other software developers (public or private)

Page 14: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Flavours Transport HTTP Sockets

Message contract SOAP XML Binary JSON HTML …

Page 15: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Technical Most API’s use HTTP and REST extensively Addressing HTTP Verbs Media types HTTP status codes Hypermedia (*)

Page 16: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control
Page 17: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control
Page 18: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

The Web is an API

Demo

Page 19: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

HTTP Verbs

GET – return data

HEAD – check if the data exists

POST – create or update data

PUT – put data

MERGE – merge values with existing data

DELETE – delete data

Page 20: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Status codes 200 OK – Everything is OK, your expected data is in the response.

401 Unauthorized – You either have to log in or you are not allowed to access the resource.

404 Not Found – The resource could not be found.

500 Internal Server Error – The server failed processing your request.

Page 21: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Hypermedia in action!

Page 22: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

dem

o

Be detailed!Remember the RFC!

Think RFC2324!

Page 23: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

ASP.NET Web API

Page 24: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

ASP.NET Web API Part of ASP.NET MVC 4

Framework to build HTTP Services (REST)

Solid features Modern HTTP programming model Content negotiation (e.g. xml, json, ...) Query composition (OData query support) Model binding and validation (conversion to .NET objects) Routes Filters (e.g. Validation, exception handling, ...) And more!

Page 25: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

ASP.NET Web API is easy! HTTP Verb = action

“Content-type” header = data format in

“Accept” header = data format out

Return meaningful status code

Page 26: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

dem

o

Creating an APIusing ASP.NET Web API

Demo

Page 27: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Securing your API No authentication

Basic/Windows authentication

[Authorize] attribute

Page 28: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

dem

o

Securing your API

Page 29: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

A lot of public API’s…

“your API consumer isn’t really your user,but an application acting on behalf of a user”

(or: API consumer != user)

Page 30: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth2

Page 31: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Guest badges Building owner / colleague full-access badge

Guest badge Your name on it Limited scope (only 7th floor) Limited validity (only today)

Page 32: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Guest badges +--------+ +---------------+ | |--(A)-- Can access tomorrow?-->| Resource | | | | Owner | | |<-(B)- Sure! Here’s invite ----| | | | +---------------+ | | . | | +---------------+ | |--(C)----- Was invited! ------>| | | Client | | Reception | | |<-(D)---- Here’s a badge! -----| | | | (today;7th floor) +---------------+ | | . | | +---------------+ | |--(E)------ Show badge ------->| Resource | | | | Server | | |<-(F) Sure you can get coffee! | | +--------+ +---------------+

And tomorrow, you’ll have to refresh your badge!

Page 33: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control
Page 34: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth2 +--------+ +---------------+ | |--(A)- Authorization Request ->| Resource | | | | Owner | | |<-(B)-- Authorization Grant ---| | | | +---------------+ | | . | | +---------------+ | |--(C)-- Authorization Grant -->| Authorization | | Client | | Server | | |<-(D)----- Access Token -------| | | | +---------------+ | | . | | +---------------+ | |--(E)----- Access Token ------>| Resource | | | | Server | | |<-(F)--- Protected Resource ---| | +--------+ +---------------+

Figure 1: Abstract Protocol Flow http://tools.ietf.org/html/draft-ietf-oauth-v2-31

Page 35: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Quick side note… There are 3 major authentication flows

Based on type of client

Variants possible

Page 36: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control
Page 37: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

On the web…

Page 38: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth2 – Initial flow

Page 39: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth2 – “Refresh” (one of those variants)

Page 40: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Access tokens / Refresh tokens In theory: whatever format you want

Widely used: JWT (“JSON Web Token”)

Less widely used: SWT (“Simple Web Token”)

Signed / Encrypted

Page 41: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

JWT

Header:{"alg":"none"}

Token:{"iss":"joe",

"exp":1300819380,

"http://some.ns/read":true}

Page 43: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

What you have to implement OAuth authorization server

Keep track of supported consumers

Keep track of user consent

OAuth token expiration & refresh

Oh, and your API

Page 44: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Windows AzureAccess Control Service

Page 45: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

ACS - Identity in Windows Azure Active Directory federation

Graph API

Web SSO

Link apps to identity providers using rules

Support WS-Security, WS-Federation, SAML

Little known feature: OAuth2 delegation

Page 46: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth flow using ACS

Page 47: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

dem

o

ASP.NET Web API, OAuth2, Windows Azure ACS

Page 48: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

OAuth2 delegation? You: OAuth authorization server

ACS: Keep track of supported consumers

ACS: Keep track of user consent

ACS: OAuth token expiration & refresh

You: Your API

Page 49: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Conclusion

Page 50: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Key takeaways API’s are the new apps

Valuable

HTTP

ASP.NET Web API

Windows Azure Access Control Service

Page 51: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control

Thank you!

http://blog.maartenballiauw.be

@maartenballiauw

http://amzn.to/pronuget

Page 52: OAuth-as-a-serviceusing ASP.NET Web API and Windows Azure Access Control