employee facing cross platform mobile apps

30
Employee Cross Platform Applications With WAAD, Xamarin and OAuth2 27 Feb 2014

Upload: graeme-foster

Post on 15-Aug-2015

144 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Employee Facing Cross Platform Mobile Apps

Employee Cross Platform Applications

With WAAD, Xamarin and OAuth227 Feb 2014

Page 2: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd2Page

A User StoryAs Joe, the miner,

I want to submit my timesheets on my phone, in the pub,

So I can maximise my fun in my time off.

Page 3: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd3Page

Offline Storage

Page 4: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd4Page

Bring Your Own Device

Page 5: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd5Page

Might not be a VPN

Page 6: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd6Page

Logons……..

Page 7: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd7

Agenda› Windows Azure Active Directory

› OAuth2

› Securing Web API with WAAD / OAuth2

› Xamarin.Auth (and tweaks!)

› Portable Class Libraries

› Xamarin.Android / ios

Page 8: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd8Page

“Our Time is short,but our challenges are many”Graeme Foster, 22nd February 2014

Page 9: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd9

Credentials in the Cloud›More User Databases›ADFS2›WAAD Dir Sync

Page 10: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd10Page

Windows AzureActive Directory

Page 11: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd11

Recap

› Azure Active Directory Management Portal› Users› Groups› Applications› Endpoints› Graph API

Page 12: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd12

Auth Options›WS-Fed / SAMLP - Mobile support

limited

›OAuth2– Widely supported. The future. Not an authentication protocol

›Open-Id Connect- A proper authentication protocol built on OAuth2

Page 13: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd

OAuth2 Code Grant Flow

13

HTTP GET …/authorize?client_id=12345&resource=TimesheetAPI&response_type=code&replyurl=somewhere.com&state=asdhj123302 Redirectsomewehere.com?code=4375983745989873&state=asdhj123

HTTP GET …/timesheets/1234Authorization: Bearer retdbcsdurykjsdvbzj

200 OKtoken=retdbcsdurykjsdvbzj

HTTP POST…/tokenclient_id=12345code=4375983745989873grant_type=authorization_codeclient_secret=??????

200 OK{timesheets: [ {… } ] }

Page 14: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd14

OAuth2 Implicit Flow

› Made for Mobile Devices

› Sends an access token straight back to the device

› Requires no client secret

› BUT

› It’s not how WAAD for Native Clients works

Page 15: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd15

OAuth2 – more details

› Bearer Tokens mandate SSL.

› WAAD token is a base-64 encoded JSON Web Token

› It is signed by the Authorisation Server

› Token’s have a limited life-span.› Refresh token’s are used to get new token’s

Page 16: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd16Page

Obtaining an OAuth2 Access Token

Page 17: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd17Page

Secure Web API using OAuth2 / WAAD

Page 18: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd18

Recap

› We created a new Web-API project

› We added Application entries in WAAD › Template did this automatically, but easy to do manually

› Used an OWIN Plug-in to inject OAuth2 Bearer Token authorisation

› ClaimsPrincipal appeared on thread

Page 19: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd19

Native App› Pros and Cons are out-of-scope. Let’s just assume we have to go Native!

› Try to do only UI in the Platform specific app

› Use a PCL to contain “business logic”

Page 20: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd20

Portable Class Libraries› Simple way of saying “Lowest Common Denominator set of frameworks for a range of devices”

› Compile to standard IL

› …please can I have “Profile 78”› Supports Async / Await› Runs on Xamarin Android / ios / windows phone 8

Page 21: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd21

Portable Class Libraries› No license restrictions around Xamarin any more

› Nuget packages for things like HttpClient

› Make it easier to create “sans UI” shared libraries

Page 22: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd22Page

Shared PCL ViewModel library

Page 23: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd23

OAuth2 in Xamarin› MS have native libraries› Creating Xamarin bindings is an option

› Auth0 – abstracts OAuth2 implementations

› Xamarin.Auth – simple open-source library

Page 24: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd24

Xamarin.Auth› Almost great› Caters for Google / Facebook / Twitter (what more could you want!)

› Azure Active Directory OAuth2 is slightly out-of-the-ordinary

› Required tweaking to work› Wanted to follow 302 redirects…

Page 25: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd25Page

WAAD OAuth2 Client in Xamarin

Page 26: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd26

Recap› Registered a Client Application in WAAD

› Used VS / Xamarin Integration› Get to use R#!

› Android Emulators are SLOW!› Geny Motion Android Emulator

› Used Xamarin Build Host to debug into ios App

Page 27: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd27

Achivements Unlocked› Corporate Credentials in the Cloud

› An API which is secured by WAAD

› A shared code library containing the guts of the Client App

› An Android and ios native client that can access the API

Page 28: Employee Facing Cross Platform Mobile Apps

Page / Copyright ©2014 by Readify Pty Ltd28

References› http://www.cloudidentity.com/blog/2013/07/23/securing-a-web-api-with-windows-azure-ad-and

-katana/

› http://xamarin.com/

› http://oauth.net/2/

› http://openid.net/connect/

› http://www.windowsazure.com/en-us/services/active-directory/

› http://www.google.com

› https://github.com/xamarin/Xamarin.Auth (fork at graemefoster@github)

› http://self-issued.info/docs/draft-ietf-oauth-json-web-token.html

› http://www.genymotion.com/

› http://www.nuget.org/packages/Microsoft.Owin.Security.ActiveDirectory

Page 29: Employee Facing Cross Platform Mobile Apps

/ Copyright ©2014 by Readify Pty Ltd29Page

[email protected]

http://gograemefoster.blogspot.com

+61 (416) 848-234

@graefoster

Page 30: Employee Facing Cross Platform Mobile Apps

Thank you