50
Apps AuthN + AuthZ Mads Damgård Senior Premier Field Engineer [email protected]

Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Embed Size (px)

Citation preview

Page 1: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Apps AuthN + AuthZ

Mads DamgårdSenior Premier Field [email protected]

Page 2: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Agenda

AuthZPrincipals

Intro

AuthNTrust

Page 3: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

About Mads Damgård

10 years with SharePoint (7 in MS)

Work interests: Dev, Troubleshooting, Search, SQL, Training

Non-work: MTB, Watersports, Travel

Page 4: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Principals

Page 5: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Principals SharePoint has long had the notion of a User Principal: europe\madsd fbaMembers:madsd i:0e.t|aad|[email protected]

The methods for dealing with User Principals are well known: SharePoint groups Permission levels Adding attributes about the user (identity or claim) to one

of the above

What about App Principals though?

Page 6: Contoso ? View Contoso View, Upload, Tag, Comment Contoso
Page 7: Contoso ? View Contoso View, Upload, Tag, Comment Contoso
Page 8: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Contoso photo

Page 9: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Contoso

Contoso photo

Page 10: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

?

Contoso

Contoso photo

Page 11: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Contoso

Contoso photo

Page 12: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

View

View

Contoso

Contoso photo

Page 13: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

View, Upload, Tag, Comment

View, Upload, Tag, Comment

Contoso

Contoso photo

Page 14: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

View, Upload, Tag, Comment, Change Password

View, Upload, Tag, Comment, Change Password

Contoso

Contoso photo

Page 15: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

View, Upload, Tag, Comment, Change Password

Contoso

Contoso photo

Page 16: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

View, Upload, Tag, Comment, Change Password

View

Contoso

Contoso photo

Page 17: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

User Principal and App Principal Context

User credentialsprovided?

Start

End

User only context

App only context

User + App

context

Anonymous context

App tokenprovided?

App tokenIncludes user?

Yes

No

No No

Yes Yes

Call is to an app web?

No

Yes

Page 18: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Apps Authentication

Page 19: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Two ways to access SharePoint Client Side

SharePoint Hosted Apps Cloud/Provider Hosted Apps (Client Side)= Direct Calls or Cross Domain Calls

Remote Server Side Cloud/Provider Hosted Apps= Access Token (Low Trust)

Server to Server= Access Token (High Trust)

Page 20: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Cross Domain Calls blocked by mostbrowsers

Examples are: Remote Web ->App Web App Web -> Host Web

Use SP.RequestExecutor.js Will post the requests through a hidden iFrame

Page 21: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Low Trust

Page 22: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

ClientResource server

Resource owner

Authorization server

Page 23: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

App.comSharePointBrowser

ACS

Page 24: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

1

App.comSharePointBrowser

ACS

1) User browses to a SharePoint page with an app part on it.

Page 25: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

1

App.comSharePointBrowser

ACS

2) SharePoint requests a context token.

2

Page 26: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

1

App.comSharePointBrowser

ACS

3) ACS returns a signed context token.

32

Page 27: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

1

App.comSharePointBrowser

ACS

4) SharePoint renders page with iframe which will POST the context token to App.com.

3

4

POST https://app.com/…SPAppToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.e…

Page 28: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

1

App.comSharePointBrowser

ACS

5) iframe causes browser to request contents from App.com including the context token.

3

4

5

Page 29: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

1

App.comSharePointBrowser

ACS

6) App.com validates the signature on the context token, extracts the auth code, and uses its credentials to request an access token from ACS.

3

4

5

6

Page 30: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

App.comSharePointBrowser

ACS

7) Windows Azure Access Control Services (ACS) returns an access token.

3

1

4

5

6 7

Page 31: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

1

App.comSharePointBrowser

ACS

8) App.com calls SharePoint CSOM or REST API with access token.

3

4

5

6 7

8

Page 32: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

App.comSharePointBrowser

ACS

9) SharePoint returns data from CSOM or REST API call.

3

1

4

5

6 7

8

9

Page 33: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

2

1

App.comSharePointBrowser

ACS

10) App.com returns the iframe contents.

3

4

5

6 7

8

9

10

Page 34: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

App.comSharePointBrowser

ACS

5

6 7

8

Context

Access /Refresh

Access

OAuth token summary

Page 35: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Context token format - Base 64 EncodedSPAppToken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhZDY5NmU1NS0zZjMzLTQwNzgtYjM2Ny0yZTdiNzVkNjQ1ZjIvbG9jYWxob3N0OjQ0MzAwQDJjNDM5MzMwLTY4NWUtNGMxMy04MTdiLWUwNTdiOTYzN2FkMCIsImlzcyI6IjAwMDAwMDAxLTAwMDAtMDAwMC1jMDAwLTAwMDAwMDAwMDAwMEAyYzQzOTMzMC02ODVlLTRjMTMtODE3Yi1lMDU3Yjk2MzdhZDAiLCJuYmYiOjEzNTI2NjU2NDUsImV4cCI6MTM1MjcwODg0NSwiYXBwY3R4c2VuZGVyIjoiMDAwMDAwMDMtMDAwMC0wZmYx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wIjoidHJ1ZSJ9.c4gAOr-4OsWo-M54t1WRT0OrjVHtl2c7jpK4N5Hbof4

Page 36: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Context token format - Decoded JSON{ "aud":ad696e55-3f33-4078-b367-2e7b75d645f2/localhost:44300@2c439330-685e-4c13-817b-e057b9637ad0 "iss":00000001-0000-0000-c000-000000000000@2c439330-685e-4c13-817b-e057b9637ad0 "nbf":2012-11-11 20:27:25Z (11/11/2012 12:27:25 PM) - 1352665645 "exp":2012-11-12 08:27:25Z (11/12/2012 12:27:25 AM) - 1352708845 "appctxsender":00000003-0000-0ff1-ce00-000000000000@2c439330-685e-4c13-817b-e057b9637ad0 "appctx":{ "CacheKey":"BSiK8SfA/eVNeMMtIJcVBO3lI5LXcPc7JwIG2XcjX4w=“ "SecurityTokenServiceUri":"https://accounts.accesscontrol.windows.net/tokens/OAuth/2" } "refreshtoken":IAAAAKBCoPpo-EVoOgwA0fwH5PWw… "isbrowserhostedapp":true}

Page 37: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

The process for hooking up an on-premise farm to use low trust is: Create an o365 tenancy; it doesn’t need any user licenses Replace the token signing certificate for the local SharePoint STS Set up an Azure Service Application Proxy, SPTrustedSecurityTokenIssuer, and SPNs

for the MsolServicePrincipal

Good news! Just follow guide and run the script found here: http://msdn.microsoft.com/en-us/library/dn155905.aspx

Low Trust Plumbing

Page 38: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

High Trust

Page 39: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Unlike low trust apps, you don’t get a context token

You have to use a certificate to sign the token your app sends to SharePoint

Register the certificate in SharePoint using PowerShell

High Trust Plumbing

Page 40: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Use the VS wizard and select provider-hosted, then select the cert (pfx), type its password, and enter the Issuer (App) ID

Place the cert in a directory that the web’s app pool has access rights

Create your client context using TokenHelper and enjoy the OAuth power that ensues!!

High Trust Plumbing – Building An App

Page 41: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

It’s called high trust for a reason – YOU control what user identity is put in the token

That identity is “rehydrated” by finding a matching user in the UPA

It’s up to you to create a token with appropriate identifier value Account name (AKA nameId) SMTP UPN SIP

High Trust Management

Page 42: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

You can choose to have each app use its own cert, or have apps share a cert

Each cert that’s used needs to be trusted by SharePoint using the New-SPTrustedSecurityTokenIssuer cmdlet

That is important if you ever want to stop trusting an app

If each app has it’s own cert, you just stop trusting that cert If apps share a cert, then you need to:

Stop trusting the cert Have all the other apps you still trust start using a new cert Configure SharePoint to start trusting the new cert

Using Certificates for High Trust Apps

Page 43: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Apps Authorization

Page 44: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Consent Form

Page 45: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Permission requestsApps request the permissions they require to run:

<AppPermissionRequests AllowAppOnlyPolicy="true"> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"> <Property Name="BaseTemplateId" Value="101"/> </AppPermissionRequest> <AppPermissionRequest Scope="http://sharepoint/social/microfeed" Right="Manage"/> <AppPermissionRequest Scope="http://sharepoint/search" Right="Query"/></AppPermissionRequests>

<AppPermissionRequest Scope="http://sharepoint/content/sitecollection" Right="Read"/>

ProductPermission ProviderSpecific component Capability

Page 46: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Available app permissions

Scope Scope Alias Right

http://sharepoint/content/tenant AllSitesRead;Write;Manage;FullControl

http://sharepoint/content/sitecollection SiteRead;Write;Manage;FullControl

http://sharepoint/content/sitecollection/web WebRead;Write;Manage;FullControl

http://sharepoint/content/sitecollection/web/list

ListRead;Write;Manage;FullControl

http://sharepoint/bcs/connectionNone (not currently supported)

Read

http://sharepoint/search SearchQueryAsUserIgnoreAppPrincipal

http://sharepoint/projectserver ProjectAdmin Manage

http://sharepoint/projectserver/projects Projects Read;Writehttp://sharepoint/projectserver/projects/project

Project Read;Write

http://sharepoint/projectserver/enterpriseresources

ProjectResources Read;Write

http://sharepoint/projectserver/statusing ProjectStatusing SubmitStatus

http://sharepoint/projectserver/reporting ProjectReporting Read

http://sharepoint/projectserver/workflow ProjectWorkflow Elevate

http://sharepoint/social/tenant AllProfilesRead;Write;Manage;FullControl

http://sharepoint/social/core SocialRead;Write;Manage;FullControl

http://sharepoint/social/microfeed MicrofeedRead;Write;Manage;FullControl

http://sharepoint/taxonomy TermStore Read;Write

Page 47: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Permission Policies User Only

Same as SharePoint 2010

App + User Both User and App needs permission to execute Apps can be installed by Site Owner Most common

App Only Provider Hosted Only Site Collection or Tenant Admin permissions to

install Similar to ”RunWithElevatedPriv”

Page 48: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Recap Authentication

Depends on Client side or Server side call model Depends on Trust model

Authorization Depends on policy model Defined in AppManifest

Page 50: Contoso ? View Contoso View, Upload, Tag, Comment Contoso

Thank You!Questions?