SlideShare a Scribd company logo
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
Who am I?

Maarten Balliauw
Technical Evangelist, JetBrains
MyGet.org
AZUG
Focus on web
 ASP.NET MVC, Windows Azure, SignalR, ...
 MVP Windows Azure & ASPInsider

Buy me a beer! http://amzn.to/pronuget
http://blog.maartenballiauw.be
   Shameless self promotion: Pro NuGet -
@maartenballiauw
   http://amzn.to/pronuget
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
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
    Hypermedia (*)
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.
…
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
Demo
Securing your API

No authentication
Basic/Windows authentication
[Authorize] attribute
Demo
The world of API clients is complex


 CLIENTS                   AUTHN + AUTHZ

 HTML5+JS                  Username/password?
 SPA                       Basic auth?
 Native apps               NTLM / Kerberos?
 Server-to-server          Client certificate?
                           Shared secret?
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
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
TechDays badges


 “I received a ticket with a Barcode I can hand to
  the Reception which gives me a Badge stating
   Microsoft gives Me access to Kinepolis as a
              Speaker on 5-7 March”
TechDays badges

         +--------+                               +---------------+
         |        |--(A)– Register for TechDays-->|   Resource    |
         |        |                               |     Owner     |
         |        |<-(B)-Sure! Here’s an e-ticket-|   Microsoft   |
         |        |                               +---------------+
         |        |                                               .
         |        |                               +---------------+
         | Client |--(C)----- Was invited! ------>| Authorization |
         |   Me   |                               |     Server    |
         |        |<-(D)---- Here’s a badge! -----|   Reception   |
         |        |        (5-7 March;speaker)    +---------------+
         |        |                                               .
         |        |                               +---------------+
         |        |--(E)------ Show badge ------->|    Resource   |
         |        |                               |     Server    |
         |        |<-(F)-- Enter speakers room ---|    Kinepolis |
         +--------+                               +---------------+

                  Next year, I will have to refresh my badge
TechDays badges

 “I received a ticket with a Barcode I can hand to the Reception which gives me a
Badge stating Microsoft gives Me access to Kinepolis as a Speaker on 5-7 March”


             Me = Client
Delegation




             Barcode = Access Code
             Reception = Authorization Server
             Microsoft = Resource Owner
             Kinepolis = Resource Server
             Badge = Access Token
             Speaker = Scope
             5-7 March = Token Lifetime
OAuth-as-a-service using 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
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
Demo
Quick side note…

There are 3 major authentication flows
Based on type of client
Variants possible
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
JWT

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
http://blogs.msdn.com/b/vbertocci/archive/2013/01/02/oauth-2-0-and-sign-in.aspx
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
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
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
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
OAuth2
Windows Azure Access Control Service
http://blog.maartenballiauw.be
                         @maartenballiauw

                   http://amzn.to/pronuget
Thank you!

More Related Content

PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
PDF
Distributed Identities with OpenID
PDF
Distributed Identities with OpenID
PDF
Hostingultraso romania
PPTX
nota lukisan persembahan senibina
PDF
01 intro(prehistoric)
PPT
The Architecture Profession
PPT
Prinsip rekaan premis makanan
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control
Distributed Identities with OpenID
Distributed Identities with OpenID
Hostingultraso romania
nota lukisan persembahan senibina
01 intro(prehistoric)
The Architecture Profession
Prinsip rekaan premis makanan

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

PPTX
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - W...
PDF
When and Why Would I use Oauth2?
PPTX
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
PDF
OAuth: Trust Issues
PDF
Draft Ietf Oauth V2 12
PPTX
OAuth - Don’t Throw the Baby Out with the Bathwater
PDF
OAuth 2.0 & OpenID Connect @ OpenSource Conference 2011 Tokyo #osc11tk
PDF
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
PPTX
Enterprise Access Control Patterns for Rest and Web APIs
PPTX
Making Sense of API Access Control
PDF
OAuth 1.0
PDF
Stateless authentication for microservices
PPTX
PPTX
Enterprise Access Control Patterns for REST and Web APIs Gluecon 2011, Franco...
PPTX
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
PDF
Stateless authentication for microservices applications - JavaLand 2015
PDF
OAuth2
PDF
CIS14: Working with OAuth and OpenID Connect
PPTX
OAuth2 + API Security
PDF
Analyzing OAuth
OAuth-as-a-service using ASP.NET Web API and Windows Azure Access Control - W...
When and Why Would I use Oauth2?
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth: Trust Issues
Draft Ietf Oauth V2 12
OAuth - Don’t Throw the Baby Out with the Bathwater
OAuth 2.0 & OpenID Connect @ OpenSource Conference 2011 Tokyo #osc11tk
Understanding Identity in the World of Web APIs – Ronnie Mitra, API Architec...
Enterprise Access Control Patterns for Rest and Web APIs
Making Sense of API Access Control
OAuth 1.0
Stateless authentication for microservices
Enterprise Access Control Patterns for REST and Web APIs Gluecon 2011, Franco...
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Stateless authentication for microservices applications - JavaLand 2015
OAuth2
CIS14: Working with OAuth and OpenID Connect
OAuth2 + API Security
Analyzing OAuth
Ad

More from Microsoft Developer Network (MSDN) - Belgium and Luxembourg (20)

PPTX
Code in the Cloud - Ghent - 20 February 2015
PPTX
Executive Summit for ISV & Application builders - January 2015
PDF
Executive Summit for ISV & Application builders - Internet of Things
PPTX
Executive Summit for ISV & Application builders - January 2015
PPTX
PPTX
cloud value for application development
PPTX
PPTX
Inside the Microsoft TechDays Belgium Apps
PPTX
PPTX
PPTX
Applied MVVM in Windows 8 apps: not your typical MVVM session!
PPTX
Building SPA’s (Single Page App) with Backbone.js
PPTX
Deep Dive and Best Practices for Windows Azure Storage Services
PPTX
Building data centric applications for web, desktop and mobile with Entity Fr...
Code in the Cloud - Ghent - 20 February 2015
Executive Summit for ISV & Application builders - January 2015
Executive Summit for ISV & Application builders - Internet of Things
Executive Summit for ISV & Application builders - January 2015
cloud value for application development
Inside the Microsoft TechDays Belgium Apps
Applied MVVM in Windows 8 apps: not your typical MVVM session!
Building SPA’s (Single Page App) with Backbone.js
Deep Dive and Best Practices for Windows Azure Storage Services
Building data centric applications for web, desktop and mobile with Entity Fr...
Ad

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

  • 2. Who am I? Maarten Balliauw Technical Evangelist, JetBrains MyGet.org AZUG Focus on web  ASP.NET MVC, Windows Azure, SignalR, ...  MVP Windows Azure & ASPInsider Buy me a beer! http://amzn.to/pronuget http://blog.maartenballiauw.be Shameless self promotion: Pro NuGet - @maartenballiauw http://amzn.to/pronuget
  • 3. Agenda Why would I need an API? API characteristics ASP.NET MVC Web API Windows Azure ACS
  • 4. Why would I need an API?
  • 5. 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)
  • 7. Twitter & Facebook By show of hands
  • 8. Make everyone API (as the French say)
  • 9. Expose services to 3rd parties Valuable Flexible Managed Supported Have a plan
  • 11. 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/
  • 13. 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)
  • 14. Flavours Transport Message contract  HTTP  SOAP  Sockets  XML  Binary  JSON  HTML  …
  • 15. Technical Most API’s use HTTP and REST extensively  Addressing  HTTP Verbs  Media types  HTTP status codes  Hypermedia (*)
  • 16. Demo
  • 17. 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
  • 18. 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. …
  • 21. 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!
  • 22. ASP.NET Web API is easy! HTTP Verb = action “Content-type” header = data format in “Accept” header = data format out Return meaningful status code
  • 23. Demo
  • 24. Securing your API No authentication Basic/Windows authentication [Authorize] attribute
  • 25. Demo
  • 26. The world of API clients is complex CLIENTS AUTHN + AUTHZ HTML5+JS Username/password? SPA Basic auth? Native apps NTLM / Kerberos? Server-to-server Client certificate? Shared secret?
  • 27. 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)
  • 30. TechDays badges “I received a ticket with a Barcode I can hand to the Reception which gives me a Badge stating Microsoft gives Me access to Kinepolis as a Speaker on 5-7 March”
  • 31. TechDays badges +--------+ +---------------+ | |--(A)– Register for TechDays-->| Resource | | | | Owner | | |<-(B)-Sure! Here’s an e-ticket-| Microsoft | | | +---------------+ | | . | | +---------------+ | Client |--(C)----- Was invited! ------>| Authorization | | Me | | Server | | |<-(D)---- Here’s a badge! -----| Reception | | | (5-7 March;speaker) +---------------+ | | . | | +---------------+ | |--(E)------ Show badge ------->| Resource | | | | Server | | |<-(F)-- Enter speakers room ---| Kinepolis | +--------+ +---------------+ Next year, I will have to refresh my badge
  • 32. TechDays badges “I received a ticket with a Barcode I can hand to the Reception which gives me a Badge stating Microsoft gives Me access to Kinepolis as a Speaker on 5-7 March” Me = Client Delegation Barcode = Access Code Reception = Authorization Server Microsoft = Resource Owner Kinepolis = Resource Server Badge = Access Token Speaker = Scope 5-7 March = Token Lifetime
  • 34. 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
  • 36. Demo
  • 37. Quick side note… There are 3 major authentication flows Based on type of client Variants possible
  • 39. OAuth2 – “Refresh” (one of those variants)
  • 40. 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
  • 41. JWT Header: {"alg":"none"} Token: {"iss":"joe", "exp":1300819380, "http://some.ns/read":true}
  • 42. 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 http://blogs.msdn.com/b/vbertocci/archive/2013/01/02/oauth-2-0-and-sign-in.aspx
  • 43. 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
  • 46. 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
  • 48. Demo
  • 49. 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
  • 51. Key takeaways API’s are the new apps Valuable HTTP ASP.NET Web API OAuth2 Windows Azure Access Control Service
  • 52. http://blog.maartenballiauw.be @maartenballiauw http://amzn.to/pronuget Thank you!