End to End Security with MVC and Web API

38
DEVintersection Session AS17 End-to-End Security for Your Web API and MVC Applications Michele Leroux Bustamante [email protected]

description

This session discussed the authentication, authorization techniques of today for web and api applications based on ASP.NET MVC and Web API.

Transcript of End to End Security with MVC and Web API

Page 1: End to End Security with MVC and Web API

DEVintersectionSession AS17

End-to-End Security for Your Web API and MVC Applications

Michele Leroux [email protected]

Page 2: End to End Security with MVC and Web API

2© DEVintersection. All rights reserved.

http://www.DEVintersection.com

Michele Leroux BustamanteManaging Partner

Solliance (solliance.net) CEO and Cofounder

Snapboard (snapboard.com)

Microsoft Regional Director Microsoft MVP

Author, SpeakerPluralsight courses on the way!Blog: michelebusta.com

[email protected]

@michelebusta

Page 3: End to End Security with MVC and Web API

Hello World!1992

Page 4: End to End Security with MVC and Web API

HelloWorld!

Page 5: End to End Security with MVC and Web API

Hello World!2013

Page 6: End to End Security with MVC and Web API

iPhoneWindowsPhone 8

Windows8/Surface

WPFClient

WindowsPhone 7

Android

iPad

Web API(mobile)

MVC Web

MobileBrowsers

Web API(business)

Web API(ajax)

Page 7: End to End Security with MVC and Web API

Things are complicated…

So we seek simplicity where we can

Page 8: End to End Security with MVC and Web API

WS*

HELL

WS-Eventing

WS-Addressing

SOAP

MTOM

sWa

WS-Transfer

WS-Enum

eration

DIME

WSNWS-ResourceTransfer

WSRF

OASIS Web Services Security

WS-SecurityPolicy

WS-Federation

SAML

WS-SecureConversation

WS-

Trus

t

WS-ReliableMessaging

WS-RM

Policy

WS-

Relia

bilit

y

WS-CAF

WS-BusinessActivity

WS-Coordination

WS-A

tom

icTr

ansa

ctio

n

WS-Policy

WSDL

WS-PolicyAttachment

WS-Discovery

WS-M

etadataExchange

Page 9: End to End Security with MVC and Web API

WS*

HELL

WS-Eventing

WS-Addressing

SOAP

MTOM

sWa

WS-Transfer

WS-Enum

eration

DIME

WSNWS-ResourceTransfer

WSRF

OASIS Web Services Security

WS-SecurityPolicy

WS-Federation

SAML

WS-SecureConversation

WS-

Trus

t

WS-ReliableMessaging

WS-RM

Policy

WS-

Relia

bilit

y

WS-CAF

WS-BusinessActivity

WS-Coordination

WS-A

tom

icTr

ansa

ctio

n

WS-Policy

WSDL

WS-PolicyAttachment

WS-Discovery

WS-M

etadataExchange

Page 10: End to End Security with MVC and Web API

10© DEVintersection. All rights reserved.

http://www.DEVintersection.com

Authentication / Authorization Considerations

Authentication Windows, username/password, cert WS-Federation, SAML 2.0, OAuth2 w/ OpenID

Connect Token Formats

Windows, Basic SAML 1.1, SAML 2.0, JSON Web Token (JWT),

SWT (legacy) Authorization

Roles, Claims, social scenarios and architecture Message Protection (TLS / SSL / WS*)

Page 11: End to End Security with MVC and Web API

Browsers

HTML

View JS

OK ajax

MVC

ViewController

Web APIController

Web API

Web APIController

Page 12: End to End Security with MVC and Web API

HTML

Browsers

View JS

OK ajax

MVCView

ViewViews

ViewController

View/APIController

Mobile

Devices

Page 13: End to End Security with MVC and Web API

WPF

Client

OK

Web API

APIController

Page 14: End to End Security with MVC and Web API

Windows Mobile Devices

OK

Web API

APIController

iOS Mobile Devices

OK

Android Mobile Devices

OK

WindowsClients

OK

OtherClients

OK

Page 15: End to End Security with MVC and Web API

Wherever possible choose the lowest

common denominator

Page 16: End to End Security with MVC and Web API

Demo

WebSecurity and Claims

Page 17: End to End Security with MVC and Web API

17© DEVintersection. All rights reserved.

http://www.DEVintersection.com

POINTS: WebSecurity and Claims

Initialize WebSecurity early Use ClaimsPrincipal to get all claims (Roles) Install AuthorizationAttribute as a filter, use

AllowAnonymousAttribute Use AuthorizationAttribute to prevent access by roles Create utilities to streamline use of claims

Page 18: End to End Security with MVC and Web API

Demo

Enabling WIF Sessions

Page 19: End to End Security with MVC and Web API

19© DEVintersection. All rights reserved.

http://www.DEVintersection.com

POINTS: WIF Sessions

Create a custom SessionAuthenticationModule Encapsulate cookie write/delete,

ClaimsPrincipal create For Forms redirect, need WebSecurity enabled

Must delete forms cookie + session cookie Other WIF best practices

Use SSL Server side session cookies (space, load

balancing) Shared token cache (replay detection, load

balancing)

Page 20: End to End Security with MVC and Web API

20© DEVintersection. All rights reserved.

http://www.DEVintersection.com

POINTS: Additional WIF Techniques

ClaimsAuthenticationManager Transform claims from user authentication

into application claims (assumes stored by app)

ClaimsAuthorizationManager Use with custom AuthorizationAttribute See Thinktecture library

ClaimsPrincipalPermission DO NOT USE

Page 21: End to End Security with MVC and Web API

Demo

Calling Web API

Page 22: End to End Security with MVC and Web API

22© DEVintersection. All rights reserved.

http://www.DEVintersection.com

POINTS: Web API Calls

Must authenticate calls to Web API Trusted Subsystem

No need to authenticate the user again Provide a key (Windows, Certificate, signed

token) JWT

New preferred way to send lightweight token Pass user claims relevant to downstream

services

Page 23: End to End Security with MVC and Web API

23© DEVintersection. All rights reserved.

http://www.DEVintersection.com

Social Login and User Consent

OAuth 2.0 Supports variations of passive and active federation Popular for used for user consent flows where an applications

wants access to user information from another applications Sharing flickr photos Sharing tweets Facebook integration

NOT for authentication Authentication

Twitter Facebook Connect OpenID Connect

Page 24: End to End Security with MVC and Web API

User Consent

Browser

ClientApplication

Authorization Server

LoginPage

1

2

5

3

4

ResourceServer

Authorization Code

Store Tokens

Get access token

Access + refresh token

Request information

Requested Information

6

7

98

10

Requested Information

11

Page 25: End to End Security with MVC and Web API

25© DEVintersection. All rights reserved.

http://www.DEVintersection.com

Social Login / Delegated Authorization

Typical choices for B-to-B Username/password Twitter Linked In

Typical choices for B-to-C Username/password Twitter Facebook (maybe) Google+

Corporate environments Windows Username/password Live ID

Page 26: End to End Security with MVC and Web API

Registration Options

Page 27: End to End Security with MVC and Web API

Create Account

Page 28: End to End Security with MVC and Web API

Facebook Registration

Page 29: End to End Security with MVC and Web API

Facebook Registration (2)

Page 30: End to End Security with MVC and Web API

Twitter Registration

Page 31: End to End Security with MVC and Web API

Social Login

Page 32: End to End Security with MVC and Web API

Demo

Social Login

Page 33: End to End Security with MVC and Web API

33© DEVintersection. All rights reserved.

http://www.DEVintersection.com

Login or Register?

Make both available Make it obvious Navigation bar is one option

Page 34: End to End Security with MVC and Web API

Access Control & Twitter

Your App

AccessControl

Google

Yahoo!Windows

Live

FaceBook

Browser

1 26 5

Your STS

3

Twitter4

Page 35: End to End Security with MVC and Web API

Your App & Facebook / Twitter

Your App

Twitter

FaceBook

Browser

OAuthWebSecurity

Page 36: End to End Security with MVC and Web API

Access Control, Social & Azure AD (vision)

Your App

AccessControl

Google

Yahoo!Windows

Live

FaceBook

Browser

Twitter

UserProfile

AzureAD

Page 37: End to End Security with MVC and Web API

37© DEVintersection. All rights reserved.

http://www.DEVintersection.com

Identity and Access Management Tools

Windows Azure Active Directory Sync directories with domain Spin up new directories Connect with other IdP

Thinktecture Code base for IdP and Authorization Server Fully functional, you own it, you can edit it WS-Fed and OAuth2, SAML2 coming

Auth0 Hosted model, affordable, from small bus to enterprise When you don’t want to own the code, need IdP, Authorization

Server/OpenID Connect support

Page 38: End to End Security with MVC and Web API

38© DEVintersection. All rights reserved.

http://www.DEVintersection.com

References

Conference resources: http://michelebusta.com

See my snapboards: Currently at the alpha site:

http://snapboardalpha.cloudapp.net/michelebusta Will move these to snapboard.com/michelebusta when we go

live on the main site (SOON watch my blog for announcement) Contact me:

[email protected] @michelebusta