SlideShare a Scribd company logo
OAuth-as-a-service
using ASP.NET Web API and Windows Azure
              Access Control
  Maarten Balliauw - @maartenballiauw
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - WebNetConf
Thanks to the sponsors
Who am I?
•   Maarten Balliauw
•   Antwerp, Belgium
•   www.realdolmen.com
•   Focus on web
    – ASP.NET MVC, Windows Azure, SignalR, ...
    – MVP Windows Azure & ASPInsider
•   http://blog.maartenballiauw.be
•   @maartenballiauw
•   Author: Pro NuGet - http://amzn.to/pronuget
•   www.myget.org
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - WebNetConf
Agenda
•   Why would I need an API?
•   API characteristics
•   ASP.NET MVC Web API
•   Windows Azure ACS
WHY WOULD I NEED AN API?
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)
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - WebNetConf
TWITTER & FACEBOOK
By show of hands…
MAKE EVERYONE API
(as the French say)
Expose services to 3rd parties
•   Valuable
•   Flexible
•   Managed
•   Supported
•   Have a plan
Reach More Clients
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/
API CHARACTERISTICS
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)
Flavours
• Transport      • Message contract
  – HTTP           – SOAP
  – Sockets        – XML
                   – Binary
                   – JSON
                   – HTML
                   –…
Technical
• Most API’s use HTTP and REST extensively
  – Addressing
  – HTTP Verbs
  – Media types
  – HTTP status codes
THE WEB IS AN API
Demo
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
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.
• …
BE DETAILED!
Think RFC2324!
ASP.NET WEB API
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!
ASP.NET Web API is easy!
•   HTTP Verb = action
•   “Content-type” header = data format in
•   “Accept” header = data format out
•   Return meaningful status code
CREATING AN API USING ASP.NET WEB API
Demo
Securing your API
• No authentication
• Basic/Windows authentication
• [Authorize] attribute
SECURING YOUR API
Demo
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)
OAUTH2
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
Guest badges
• Building owner / colleague full-access badge
• Guest badge
  – Your name on it
  – Limited scope (only 7th floor)
  – Limited validity (only today)
OAuth2
                +--------+                               +---------------+
                |        |--(A)- Can has guest access? ->|   Building    |
                |        |                               |     Owner     |
                |        |<-(B)– Sure, ask reception ---|                |
                |        |                               +---------------+
                |        |                                               .
                |        |                               +---------------+
                |        |--(C)–--- Can has badge? ----->|   Reception   |
                | Client |                               |               |
                |        |<-(D) Badge (today;7th floor) -|               |
                |        |                               +---------------+
                |        |                                               .
                |        |                               +---------------+
                |        |--(E)-------- Badge ---------->|   7th floor   |
                |        |                               |    coffee     |
                |        |<-(F)-------- Coffee! ---------|    machine    |
                +--------+                               +---------------+

By the way: tomorrow, you’ll have to go to the reception again to “refresh” your badge.
Quick side note…
• There are 3 major authentication flows
• Based on type of client
• Variants possible
On the web…
OAuth2 – Initial flow
OAuth2 – “Refresh” (one of those variants)
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
Header:
{"alg":"none"}

Token:
{"iss":"joe",
   "exp":1300819380,
   "http://some.ns/read":true}
Is OAuth2 different from OpenID?
• Yes.
• OpenID = authN
• OAuth2 = authN (optional) + authZ

• http://softwareas.com/oauth-openid-youre-
  barking-up-the-wrong-tree-if-you-think-theyre-
  the-same-thing
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
WINDOWS AZURE
ACCESS CONTROL SERVICE
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
OAuth flow using ACS
ASP.NET WEB API, OAUTH2, WINDOWS AZURE ACS
Demo
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
CONCLUSION
Key takeaways
•   API’s are the new apps
•   Valuable
•   HTTP
•   ASP.NET Web API
•   Windows Azure Access Control Service
Thank you!
                    http://blog.maartenballiauw.be
                    @maartenballiauw




Please rate this session
Scan the code, go online, rate this session

More Related Content

PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
PPTX
ASP.NET WEB API
PPTX
ASP.NET Web API and HTTP Fundamentals
PPTX
The Full Power of ASP.NET Web API
PPTX
Web development with ASP.NET Web API
ODP
Web Server-Side Programming Techniques
PPTX
ASP.NET Mvc 4 web api
PPTX
Web services - A Practical Approach
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
ASP.NET WEB API
ASP.NET Web API and HTTP Fundamentals
The Full Power of ASP.NET Web API
Web development with ASP.NET Web API
Web Server-Side Programming Techniques
ASP.NET Mvc 4 web api
Web services - A Practical Approach

What's hot (20)

PPT
Excellent rest using asp.net web api
PDF
Server-side Java Programming
PPTX
ASP.NET WEB API Training
PDF
Server-Side Programming Primer
PPTX
Servletarchitecture,lifecycle,get,post
PPT
Web servers
PDF
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
PDF
HTML5 Refresher
PDF
HTML5 Server Sent Events/JSF JAX 2011 Conference
PPTX
The ASP.NET Web API for Beginners
PPTX
Introduction to asp.net web api
PPT
Alfresco Architecture
PDF
SOAP-based Web Services
PDF
ITB2016 - Building ColdFusion RESTFul Services
PDF
Spring Web Services: SOAP vs. REST
PDF
Building Restful Applications Using Php
PPTX
Java servlets and CGI
PDF
OAuth: Trust Issues
PPT
Web services intro.
PPT
Introduction server Construction
Excellent rest using asp.net web api
Server-side Java Programming
ASP.NET WEB API Training
Server-Side Programming Primer
Servletarchitecture,lifecycle,get,post
Web servers
2009 - Microsoft IIS Vs. Apache - Who Serves More - A Study
HTML5 Refresher
HTML5 Server Sent Events/JSF JAX 2011 Conference
The ASP.NET Web API for Beginners
Introduction to asp.net web api
Alfresco Architecture
SOAP-based Web Services
ITB2016 - Building ColdFusion RESTFul Services
Spring Web Services: SOAP vs. REST
Building Restful Applications Using Php
Java servlets and CGI
OAuth: Trust Issues
Web services intro.
Introduction server Construction
Ad

Viewers also liked (10)

PPTX
What's new in Angular 2?
PPTX
Introduction to AngularJS
PPTX
Introduction to HTML4
PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
PPTX
Web API with ASP.NET MVC by Software development company in india
PPTX
REST and ASP.NET Web API (Milan)
PPTX
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
PDF
C# ASP.NET WEB API APPLICATION DEVELOPMENT
PDF
29 Essential AngularJS Interview Questions
PPTX
Javaoop
What's new in Angular 2?
Introduction to AngularJS
Introduction to HTML4
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
Web API with ASP.NET MVC by Software development company in india
REST and ASP.NET Web API (Milan)
OAuth with AngularJS and WebAPI - SoCal Code Camp 2015
C# ASP.NET WEB API APPLICATION DEVELOPMENT
29 Essential AngularJS Interview Questions
Javaoop
Ad

Similar to OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - WebNetConf (20)

PPTX
OAuth-as-a-service - using ASP.NET Web API and Windows Azure Access Control -...
PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
PDF
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
PDF
Distributed Identities with OpenID
PDF
Distributed Identities with OpenID
PDF
Draft Ietf Oauth V2 12
PPTX
OAuth - Don’t Throw the Baby Out with the Bathwater
PPTX
Enterprise Access Control Patterns for Rest and Web APIs
PDF
How to Build, Manage, and Promote APIs
PPTX
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
PDF
When and Why Would I use Oauth2?
PDF
Stateless token-based authentication for pure front-end applications
PPTX
OAuth 2
PDF
CIS14: Working with OAuth and OpenID Connect
PPTX
How to build Simple yet powerful API.pptx
PDF
Stateless authentication for microservices applications - JavaLand 2015
PDF
Protecting Your APIs Against Attack & Hijack
PPTX
API Management and Mobile App Enablement
PDF
Stateless authentication for microservices
PDF
CIS13: Introduction to OAuth 2.0
OAuth-as-a-service - using ASP.NET Web API and Windows Azure Access Control -...
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
Distributed Identities with OpenID
Distributed Identities with OpenID
Draft Ietf Oauth V2 12
OAuth - Don’t Throw the Baby Out with the Bathwater
Enterprise Access Control Patterns for Rest and Web APIs
How to Build, Manage, and Promote APIs
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
When and Why Would I use Oauth2?
Stateless token-based authentication for pure front-end applications
OAuth 2
CIS14: Working with OAuth and OpenID Connect
How to build Simple yet powerful API.pptx
Stateless authentication for microservices applications - JavaLand 2015
Protecting Your APIs Against Attack & Hijack
API Management and Mobile App Enablement
Stateless authentication for microservices
CIS13: Introduction to OAuth 2.0

More from Maarten Balliauw (20)

PPTX
Bringing nullability into existing code - dammit is not the answer.pptx
PPTX
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
PPTX
Building a friendly .NET SDK to connect to Space
PPTX
Microservices for building an IDE - The innards of JetBrains Rider - NDC Oslo...
PPTX
Indexing and searching NuGet.org with Azure Functions and Search - .NET fwday...
PPTX
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
PPTX
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
PPTX
.NET Conf 2019 - Indexing and searching NuGet.org with Azure Functions and Se...
PPTX
CloudBurst 2019 - Indexing and searching NuGet.org with Azure Functions and S...
PPTX
NDC Oslo 2019 - Indexing and searching NuGet.org with Azure Functions and Search
PPTX
Approaches for application request throttling - Cloud Developer Days Poland
PPTX
Indexing and searching NuGet.org with Azure Functions and Search - Cloud Deve...
PPTX
Approaches for application request throttling - dotNetCologne
PPTX
CodeStock - Exploring .NET memory management - a trip down memory lane
PPTX
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
PPTX
ConFoo Montreal - Approaches for application request throttling
PPTX
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
PPTX
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
PPTX
DotNetFest - Let’s refresh our memory! Memory management in .NET
PPTX
VISUG - Approaches for application request throttling
Bringing nullability into existing code - dammit is not the answer.pptx
Nerd sniping myself into a rabbit hole... Streaming online audio to a Sonos s...
Building a friendly .NET SDK to connect to Space
Microservices for building an IDE - The innards of JetBrains Rider - NDC Oslo...
Indexing and searching NuGet.org with Azure Functions and Search - .NET fwday...
NDC Sydney 2019 - Microservices for building an IDE – The innards of JetBrain...
JetBrains Australia 2019 - Exploring .NET’s memory management – a trip down m...
.NET Conf 2019 - Indexing and searching NuGet.org with Azure Functions and Se...
CloudBurst 2019 - Indexing and searching NuGet.org with Azure Functions and S...
NDC Oslo 2019 - Indexing and searching NuGet.org with Azure Functions and Search
Approaches for application request throttling - Cloud Developer Days Poland
Indexing and searching NuGet.org with Azure Functions and Search - Cloud Deve...
Approaches for application request throttling - dotNetCologne
CodeStock - Exploring .NET memory management - a trip down memory lane
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Approaches for application request throttling
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
JetBrains Day Seoul - Exploring .NET’s memory management – a trip down memory...
DotNetFest - Let’s refresh our memory! Memory management in .NET
VISUG - Approaches for application request throttling

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Approach and Philosophy of On baking technology
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Big Data Technologies - Introduction.pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Review of recent advances in non-invasive hemoglobin estimation
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
MYSQL Presentation for SQL database connectivity
Reach Out and Touch Someone: Haptics and Empathic Computing
Approach and Philosophy of On baking technology
Advanced methodologies resolving dimensionality complications for autism neur...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
CIFDAQ's Market Insight: SEC Turns Pro Crypto
NewMind AI Weekly Chronicles - August'25 Week I
NewMind AI Monthly Chronicles - July 2025
Big Data Technologies - Introduction.pptx
20250228 LYD VKU AI Blended-Learning.pptx

OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - WebNetConf

  • 1. OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control Maarten Balliauw - @maartenballiauw
  • 3. Thanks to the sponsors
  • 4. Who am I? • Maarten Balliauw • Antwerp, Belgium • www.realdolmen.com • Focus on web – ASP.NET MVC, Windows Azure, SignalR, ... – MVP Windows Azure & ASPInsider • http://blog.maartenballiauw.be • @maartenballiauw • Author: Pro NuGet - http://amzn.to/pronuget • www.myget.org
  • 6. Agenda • Why would I need an API? • API characteristics • ASP.NET MVC Web API • Windows Azure ACS
  • 7. WHY WOULD I NEED AN API?
  • 8. 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)
  • 10. TWITTER & FACEBOOK By show of hands…
  • 11. MAKE EVERYONE API (as the French say)
  • 12. Expose services to 3rd parties • Valuable • Flexible • Managed • Supported • Have a plan
  • 14. 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/
  • 16. 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)
  • 17. Flavours • Transport • Message contract – HTTP – SOAP – Sockets – XML – Binary – JSON – HTML –…
  • 18. Technical • Most API’s use HTTP and REST extensively – Addressing – HTTP Verbs – Media types – HTTP status codes
  • 19. THE WEB IS AN API Demo
  • 20. 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
  • 21. 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. • …
  • 24. 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!
  • 25. ASP.NET Web API is easy! • HTTP Verb = action • “Content-type” header = data format in • “Accept” header = data format out • Return meaningful status code
  • 26. CREATING AN API USING ASP.NET WEB API Demo
  • 27. Securing your API • No authentication • Basic/Windows authentication • [Authorize] attribute
  • 29. 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)
  • 31. 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
  • 32. Guest badges • Building owner / colleague full-access badge • Guest badge – Your name on it – Limited scope (only 7th floor) – Limited validity (only today)
  • 33. OAuth2 +--------+ +---------------+ | |--(A)- Can has guest access? ->| Building | | | | Owner | | |<-(B)– Sure, ask reception ---| | | | +---------------+ | | . | | +---------------+ | |--(C)–--- Can has badge? ----->| Reception | | Client | | | | |<-(D) Badge (today;7th floor) -| | | | +---------------+ | | . | | +---------------+ | |--(E)-------- Badge ---------->| 7th floor | | | | coffee | | |<-(F)-------- Coffee! ---------| machine | +--------+ +---------------+ By the way: tomorrow, you’ll have to go to the reception again to “refresh” your badge.
  • 34. Quick side note… • There are 3 major authentication flows • Based on type of client • Variants possible
  • 37. OAuth2 – “Refresh” (one of those variants)
  • 38. 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
  • 39. Header: {"alg":"none"} Token: {"iss":"joe", "exp":1300819380, "http://some.ns/read":true}
  • 40. Is OAuth2 different from OpenID? • Yes. • OpenID = authN • OAuth2 = authN (optional) + authZ • http://softwareas.com/oauth-openid-youre- barking-up-the-wrong-tree-if-you-think-theyre- the-same-thing
  • 41. 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
  • 43. 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
  • 45. ASP.NET WEB API, OAUTH2, WINDOWS AZURE ACS Demo
  • 46. 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
  • 48. Key takeaways • API’s are the new apps • Valuable • HTTP • ASP.NET Web API • Windows Azure Access Control Service
  • 49. Thank you! http://blog.maartenballiauw.be @maartenballiauw Please rate this session Scan the code, go online, rate this session

Editor's Notes

  • #6: Maarten
  • #8: Kinepolis: veel static content / in-frame caching
  • #10: A couple of years ago, having a web-based application was enough. Users would navigate to it using their computer’s browser, do their dance and log out again. Nowadays, a web-based application isn’t enough anymore. People have smartphones, tablets and maybe even a refrigerator with Internet access on which applications can run. Applications or “apps”. We’re moving from the web towards apps.
  • #12: A great example of an API is Twitter. They have a massive data store containing tweets and data related to that. They have user profiles. And a web site. And an API. Are you using www.twitter.com to post tweets? I am using the website, maybe once a year. All other tweets come either from my Windows Phone 7’s Twitter application or through www.hootsuite.com, a third-party Twitter client which provides added value in the form of statistics and scheduling. Both the app on my phone as well as the third-party service are using the Twitter API. By exposing an API, Twitter has created a rich ecosystem which drives their real value: data.
  • #14: If you want to expose your data and services to external third-parties, you may want to think about building an API. Having an API gives you a giant advantage on the Internet nowadays. Having an API will allow your web application to reach more users. App developers will jump onto your API and build their app around it. Other websites or apps will integrate with your services by consuming your API. The only thing you have to do is expose a valuable, managed and supported API and get people to know it. Apps will come. Integration will come.
  • #15: The mainidea of API’s is tobroadenyourreach. Youcan’tcreateappsthatcanbeused on every fridge out there, it’s way toocostly. But ifyou have a valuable service which is supported, peoplewillbuildappsaround it. Andifitmakes sense toanyonetocreate a fridge app on top of your API, itwill happen.
  • #16: You’renot the onlyone. Thenumber of API’s is growing at a fast pace and the number of appsandmashups on different devicesgrowswiththat. Ifyou want market share, your best chance of growingit is in building a valuable API.
  • #18: An API is simply a software-to-software interface, defined by whoever is exposing the API to public or private users. It defines constraints, both technical as well as legal. Twitter for example defines a usage constraint: if you are using their API without paying you will be limited to a certain number or requests.
  • #22: We can inform the server of what we intend to do using one of the standard HTTP verbs. There are more verbs if you like, but these are the most widely used.
  • #23: There’s a large number possible status codes you can use. Here are some you will most commonly encounter: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.See the theme? 1XX are informational. 2XX codes mean “successful”. 3XXX tell you to go elsewhere, like our 302 example above. 4XX means the client has done something wrong. A wrong address or a wrong request. 5XX means the server has had a problem, like the feared error 500 – Internal Server Error you see on some websites.
  • #27: Here are four basic conventions for ASP.NET Web API:Requests have an HTTP verb defined. This maps to the API controller’s action method.Requests have an Accept header. This is handled by ASP.NET Web API’s MediaTypeFormatter and will transform the request to your controller from JSON, XML or whatever format you want to add as a MediaTypeFormatter.Responses have an HTTP status code.Responses are formatted by ASP.NET Web API’s MediaTypeFormatter into JSON, XML or whatever format you want to add as a MediaTypeFormatter.
  • #29: If you decide that your API isn’t public or specific actions can only be done for a certain user (get me my tweets, Twitter!), you’ll be facing authentication and authorization problems. With ASP.NET Web API, this is simple: add an [Authorize] attribute on top of a controller or action method and you’re done, right? When using the out-of-the-box authentication/authorization mechanisms of ASP.NET Web API, you are relying on either forms authentication or Windows authentication. Both require the user to log in. And as your API user isn’t really your user, but an application acting on behalf of a user, that means that the application should know the user’s credentials. Would you give your username and password to a third-party website to access your Twitter account? I don’t think so.
  • #31: I want you to remember one sentence: “your API user isn’t really your user, but an application acting on behalf of a user”. It has implications. It means you are “delegating” access to an API to a consuming application.
  • #34: Maybeyouwork at a company which hands out guest badges tovisitors. You have a badge with full access to the office, yourguests have a guest badge. Your name is on that badge: ifanythinggoes wrong or has tobedone, colleaguescanidentify the guest as someonewho’sthere on your call.The guest badge canbelimited in scope (only the 7th foor) or in validityduration (onlytoday).Wouldn’tthisbe a great approach toprotectyour API?
  • #37: As anexample, take lanyrd.com. They keep track of conferences you’llbespeaking at and conferences thepeopleyou follow on Twitter are speaking at. To get that data, theyneed access to the list of peopleyou follow on Twitter. Here’swhathappens:You want to log in on Lanyrd, theyredirectyoutoTwitter’s login page. Notice the token in the address bar: itidentifies the callingapplicationtoTwitter.You log in on Twitterandgive consent with a limited scope: Lanyrdwillbeabletoseeyourtimelineand get the list of peopleyou follow. The scope is limitedtothat: Lanyrdcan’ttweet on mybehalf. Theycan’tfavoritetweets. Or sendmessages. Or do anythingelse.Twitterredirects me back toLanyrd, posting back a “refresh” tokenWhatyoudon’tsee:Lanyrdusesthat token torequestan “access token” fromTwitter.Twitter checks the validity of the incoming token and checks the origin, to make sure no otherapplication but Lanyrdcomes in withthat token.Whenvalid, Twitter returns an access token toLanyrd, containing:An access keyA new refresh tokenThe allowed scopeValiditydurationA signature- When the token expires, Lanyrduses the new refresh token to go throughthisprocessagain.
  • #43: There’s a lot toimplement.
  • #45: One of the interesting components in the Windows Azure platform is the Access Control Service (ACS). ACS allows you to outsource your authentication and authorization woes and have Microsoft handle those. At www.myget.org, an application me and a colleague have been working on, you’ll find that you can log in through a variety of identity providers (Windows Live ID, Google, Facebook, GitHub, …). We don’t have to do anything for that: ACS solves this and presents us with a set of claims about the user, such as his username on GitHub. If we want to add another identity provider, we simply configure it in ACS and without modifying our code, you can login through that new identity provider.Next to that, ACS provides a little known feature: OAuth2 delegation support. The idea with that is that your application’s only job is to ask the user if a specific application can act on his or her behalf and store that decision in ACS. From then on, the client application will always have to go to ACS to fetch an access token and a refresh token which can be presented to your API.
  • #46: This approach comes in very handy! Every client application will only have to ask our Authorization server once for user consent, after which ACS will take care of handing out access tokens, expiring tokens, renewing tokens and so on. ACS handles all the authentication and authorization load for us, even with 1 billion apps and users consuming my API. And all of that for just 19 US$ per million actions on ACS (see pricing calculator).
  • #48: There’s a lot toimplement. Whynot outsource itto Windows Azure ACS?You: OAuthauthorization server  youdecidewho is granted access andwho’snot. You’ll have totell ACS aboutthis, but apart fromthatyou have nothingto do.ACS: Keep track of supportedconsumers based on your inputACS: Keep track of user consent  based on the user’s inputACS: OAuth token expiration &amp; refresh based on all of the aboveYou: Your API  of course!
  • #50: 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.We’re moving from the web towards apps. Next to your website, apps are becoming more and more popular as an alternative manner to consume your data and services. Why not use that as a lever to reach more users? By exposing an API, you’re giving third party app developers the opportunity to interface with your services and at the same time, they are the advocate of them. Embrace them, give them a good API.Of course, that API should be protected. OAuth2 is becoming the de-facto standard for that but requires some server-side coding on your part. If you just want to focus on the API and delegate the heavy lifting and scaling of the OAuth2 protocol, you may as well delegate it to the Windows Azure Access Control Service. WindowsAzure.Acs.Oauth2 will help you with that.