SlideShare une entreprise Scribd logo
1  sur  48
Going Mobile with
PingFederate and OAuth 2

Scott Tomilson
Technical Product Manager
Ping Identity




                            Copyright © 2012. Cloud Identity Summit. All Rights Reserved.
WELCOME
About me …



       "Who the heck is
          this guy?
       And why should I
           listen?"
About me … Scott Tomilson

• "Inside" Technical Product
  Manager for PingFederate
• Based in Vancouver, Canada
• Spent majority of career in
  Japan & Australia
• 12 years in Security / IdM
• Engineer, Consultant, Trainer
• CISSP
                                  photo kindly stolen from Brian D. Campbell
Going Mobile - PingFederate and OAuth 2

• Agenda
  – OAuth 2 & You
  – "Hands-on" with the OAuth 2 Playground
  – Break (yay!)
  – Even more "Hands-on" work
  – Mobile Integration dive: iOS & Android
  – Wrap-up
OAUTH 2 & YOU
5 reasons to love OAuth 2 (for Mobile) ?
1. You've got REST API's, you want a standard
   way to secure them
2. Your API's / applications involve sensitive
   resources that either your organization or
   end users want to control access to
3. Your API will be available to partner
   apps, but you still control user authentication
4. You need revocation capabilities
5. You / your company paid for this workshop –
   so, why the heck not!
Speaking OAuth 2 (i.e.: Terminology)

 "Actors"
 • Client - Wants access to a resource protected by a
   Resource Server and interacts with an Authorization
   Server to obtain tokens.

 • Resource Server (RS) - Hosts and protects resources
   and makes them available to properly authenticated and
   authorized clients.

 • Authorization Server (AS) - Issues access and refresh
   tokens to clients on behalf of RS's.
OAuth 2 Terminology (cont'd)
 Protocol Terms
 • Access token (AT) - Allows clients to authenticate to an RS and
   claim authorizations for accessing particular resources. Expires
   based on time (typically minutes).

 • Refresh token (RT) - Allows clients to obtain a fresh access token
   without re-obtaining authorization from the resource owner. Expires
   based on user revocation or time (typically days).

 • Authorization Code – One time code issued by an AS to be
   exchanged for an AT.

 • Scopes – A permission (or set of permissions) defined and agreed
   upon by the Client, RS and AS.
OAuth 2 Terminology (cont'd again)

 Protocol Terms (cont'd)
 • Grant Types - An authorization grant is a credential representing
   the resource owner's authorization (to access its protected
   resources) used by the client to obtain an access token. Grant
   types dictate how the authorization grant is performed (and thus
   how the token is released).
   Examples:
      • Authorization Code
      • Implicit
      • Resource Owner Password Credentials
A "TYPICAL" MOBILE OAUTH 2 DEMO
Authorization Code Grant
1.) User accesses Native Mobile Application and
requests action. Action requires user authentication            2
and/or authorization to the Resource Server (RS).

2.) Native Application launches the device's browser                   3
and requests the Authorization Server's (AS)                                       Authorization Server
authorization endpoint                                                     4         (PingFederate)
(https://<pf>/as/authorization.oauth2). Request
query string includes the OAuth client ID, request
type and requested scopes.

3.) User authenticates to Authorization Server (AS)
via IdP Adapter, or IdP Connection. After
authentication user sees confirmation page with
requested scopes and clicks "Approve".
                                                                               5
4.) AS redirects user back to the Native Mobile
Application via a custom registered scheme                   Browser
(protocol) that the application registered, and
includes an authorization code in the query string
                                                                                                   Resource Server
(e.g.: partnerapp://callback?code=xxxxx).
                                                           Native Mobile                         (REST API endpoint)
5.) Native Mobile App resolves authorization code to        Application
a token (access token [and refresh token]) via REST
API call to the AS token endpoint
(https://<pf>/as/token.oauth2).
                                                       1
Token [ Mobile Application Integration – Redirection Flow
      Native Refresh & ] Usage
             Token Refresh & Usage

1.) User accesses Native Mobile Application and
                                                                        [3]
requests action. Action requires user
authentication and/or authorization to the
Resource Server (RS).
2.) Native Mobile Application checks if user has a
valid (non-expired) access token. If none available                               Authorization Server           5
(and a refresh token is available) a request to the                                 (PingFederate)
Authorization Server (AS) token endpoint
(https://<pf>/as/token.oauth2) to obtain a new
one.
                                                            Browser
3.) AS looks up refresh token in its persistent grant
storage, and if valid, issues a new access token (and
possibly refresh token).
                                                        Native Mobile             [2]
4.) Native Mobile Application inserts the OAuth
access token in an Authorization HTTP header             Application
(Bearer type), and makes the REST API call to the
RS.
5.) RS validates incoming access token with AS
using the token endpoint                                                      4
(https://</pf>/as/token.oauth2) with a
PingFederate validation grant type. AS returns          1                                            Resource Server
validation results including user attributes.
                                                                                                   (REST API endpoint)
Authorization Code Grant




                                              Mobile example demo…




14    Copyright © 2011. Cloud Identity Summit. All Rights Reserved.
Authorization Code Grant

Protocol Details
Request:
https://as.pingidentity.com/as/authorization.oauth2?
client_id=my_app_id&response_type=code



                     ( Login … Authorize )

Callback Response:
HTTP/1.1 302 Found
Location: my_app://app.myapp.com/oauth?code=SplxlOBeZQQYbYS6WxSbIA
Authorization Code Grant

Protocol Details (cont'd)
Request:
POST /as/token.oauth2 HTTP/1.1
Host: as.pingidentity.com
Content-Type: application/x-www-form-urlencoded;charset=UTF-8

grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA


Response:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
Cache-Control: no-store
Pragma: no-cache

{"token_type":"Bearer","expires_in":60, "access_token":"PeRTSD9RQrbiuoaHVP
xV41MzW1qS"}
Token Usage

Protocol Details


GET /some/api/call HTTP/1.1
Host: rs.myapp.com
Authorization: Bearer PeRTSD9RQrbiuoaHVPxV41MzW1qS
Native Mobile Application Integration

 Getting a Token (cont’d)
 •   Open browser to authorization endpoint sample code:

 - (IBAction)doAction:(id)sender
 {
     NSLog(@"About to open Safari to OAuth AS Authorization Endpoint...");


     // In this example, use a named IDP connection for user authentication
     NSString* launchUrl =
 @"https://as.pingidentity.com/as/authorization.oauth2?client_id=mobileclient1&respons
 e_type=code&idp=partner:entity:id";


     [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]];
 }
Native Mobile Application Integration

 Getting a Token (cont’d)
 •   Registering a custom URI scheme in iOS:
Native Mobile Application Integration

 Getting a Token (cont’d)
 •   Handling parameters – sample code:

     // Parse of URL query string complete
      if (error != nil) {
         // Show error message to user
     }
     else {
         NSString *code = [qsParms objectForKey:@"code"];


         // Form HTTP POST to resolve JSON structure
         NSString *post = [NSString
 stringWithFormat:@"grant_type=authorization_code&code=%@", code];
         NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding
 allowLossyConversion:YES];
Native Mobile Application Integration

 Getting a Token (cont’d)
 •       Handling parameters – sample code (cont'd):

           NSString *postLength = [NSString stringWithFormat:@"%d",
                                 [postData length]];
        NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init]
 autorelease];
            [request setURL:[NSURL URLWithString:@"https://as.idp.com/as/token.oauth2"]];
            [request setHTTPMethod:@"POST"];
            [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
         [request setValue:@"application/x-www-form-urlencoded"
 forHTTPHeaderField:@"Content-Type"];
            [request setHTTPBody:postData];


         NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request
 delegate:self];
            if (conn) {
                receivedData = [[NSMutableData data] retain];
            }
     }
Native Mobile Application Integration

 Getting a Token (cont’d)
 •   Handling parameters – sample code (cont'd):
 - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
     // json-framework library: https://github.com/stig/json-framework/
     SBJsonParser *jsonParser = [[SBJsonParser alloc] init];
     NSString *aStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
     NSString *accessToken = nil;
     NSString *refreshToken = nil;


     id object = [jsonParser objectWithString:aStr];
     if (object) {
         NSLog(@"JSON parsed successfully.");


         if ([object isKindOfClass:[NSDictionary class]]) {
             NSDictionary *nsDict = (NSDictionary*)object;
             accessToken = [nsDict objectForKey:@"access_token"];
             refreshToken = [nsDict objectForKey:@"refresh_token"];
         }
Native Mobile Application Integration

 Using a Token (cont'd)
 •   Sample code:

 // Form the Bearer token Authorization header
 NSString *authzHeader = [NSString stringWithFormat:@"Bearer %@", accessToken];


 NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
 [request setURL:[NSURL URLWithString:@"https://rs.idp.com/msg/api"]];
 [request setValue:authzHeader forHTTPHeaderField:@"Authorization"];


 NSLog(@"Initiating URL connection to RS with access_token...");
 NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request
 delegate:self];
GETTING TO KNOW GRANT TYPES
Grant Types for Mobile

• "Using a Token" is easy (for Bearer)
• "Getting a Token" requires decisions

• Grant Types most applicable to mobile:
  – Authorization Code
  – Implicit
  – Resource Owner Password Credentials
Grant Types for Mobile
  Grant Type     Authentication   Authz   Refresh Tokens     Types of Apps
                                  Step      Support?
Authorization   Browser based      ✔           ✔           • 3rd Party App
Code                                                       • Trusted App
                                                             using Web
                                                             based Authn
Implicit        Browser based      ✔           ✖           • As above, but
                                                             lives in browser;
                                                             e.g.: JS app
Resource        Application        ✖           ✔           • Trusted App,
Owner                                                        using only
Password                                                     username/pass
Credentials                                                  word Authn
RO Password Credentials Grant Type




                                              Mobile example demo…




27    Copyright © 2011. Cloud Identity Summit. All Rights Reserved.
Comparison of Grant Types & Models

    Authorization Code (                              Resource Owner
    Embedded browser)                                   Credentials
                                    • No need to leave app context

                                                        • Password shared with 3rd party
                                                        • Application owns login UI
                           • Enables SSO
                           • Enables strong authn
                           • AS owns login UI


                               • Visual trust cues (SSL lock)
                               • Authentication can leverage stored passwords
                               • Authentication can leverage existing sessions

                           Authorization Code (
                            Separate browser )




                                                                                           28
One more thing … Client Authentication

• So, yeah - what about Client Authn?
• Possible additional security requirement
  before grant
• Limited use for mobile / client side apps…
  10.1. Client Authentication
  . . .
  The authorization server MUST NOT issue client
  passwords or other client credentials to native
  application or user-agent-based application clients
  for the purpose of client authentication. The
  authorization server MAY issue a client password or
  other credentials for a specific installation of a
  native application client on a specific device.
  . . .
  http://tools.ietf.org/html/draft-ietf-oauth-v2-30#section-10.1
Going Mobile - PingFederate and OAuth 2

• Agenda
  – OAuth 2 & You
  – "Hands-on" with the OAuth 2 Playground
  – Break
  – Even more "Hands-on" work
  – Mobile Integration dive: iOS & Android
  – Wrap-up
"HANDS-ON" WITH THE OAUTH 2.0
PLAYGROUND
PingFederate OAuth 2 Playground

• Setup hands-on activity starts now!
• On the USB thumb drives:
  – JDK 1.6 (for Windows - 32 and 64 bit)
  – PingFederate 6.8 (& trial license)
  – OAuth 2 Playground
  – LabReadme.pdf
• Follow PDF instruction to set up the lab
Going Mobile with
PingFederate and OAuth 2

Break

Back @ 2:45PM sharp!
Going Mobile - PingFederate and OAuth 2

• Agenda
  – OAuth 2 & You
  – "Hands-on" with the OAuth 2 Playground
  – Break
  – Even more "Hands-on" work
  – Mobile Integration dive: iOS & Android
  – Wrap-up
Hands-on Playground Fun

1. Enable Refresh Token grant type and test it.
   As the end user, revoke the grant.
2. Enable "Bypass" of Authorization for the
   Authorization Code use case. Test it.
3. Add a callback Redirect URL scheme to be
   myapp://. Test it – using browser trace.
4. Define additional users for Resource Owner
   Password Credentials Grant Type, and new
   AT user attribute for Department. Test it.
MOBILE INTEGRATION DIVE:
IOS & ANDROID
Mobile Integration Dive

Let's talk about the tricky bits:
• Integration Approaches
• Combining Native Apps and Browsers
  – Embedding vs. Invoking the Browser
  – Handling callbacks
• Secure Token Handling
• SSO Approaches
OAuth Mobile Integration

 Integration Approaches

 •   DIY OAuth integration – Effort level is small(-ish).
     Examples are used in this presentation. Requires:
     • Launching the browser (externally or embedded)
     • Detecting callback from the browser
     • JSON response parsing
     • Secure token handling

 •   OAuth Client Library – Provides the above
     functionality with a higher level of abstraction. E.g.:
     • Google Toolbox for Mac – OAuth 2 Controllers:
        http://code.google.com/p/gtm-oauth2/

                                                               38
Embedding vs. Invoking the Browser
           Embedding                               Invoking
    (Android WebView / iOS UIWebView)             (External Browser)

Pros:                                   Pros:
• Seamless user experience              • Full, trusted browser UI
• More options for callback             • Share existing authn sessions
  handling (e.g.: cookies, title)         (WAM SSO)
• Better for some MITM attacks

Cons:                                   Cons:
• May look suspect to savvy users       • Different default browsers –
• Doesn't share cookies                   custom scheme URI's may not
                                          be handled (Opera on Android)
Handling Callbacks – Embedded Browser

Ways a native app could get the callback
(authorization code):
1. Cookies – Name of the cookie is agreed
   upon
2. Window Title – Code is in the HTML
   <title> tag, which can be read by
   native app.
    • May be vulnerable to leaks if the website has
      cross-site scripting bugs.
Handling Callbacks – Invoked Browser

Ways a native app could get the callback
(authorization code):
1. Custom URI Scheme – myapp://
2. Registered Intent for Scheme/Host –
   https://oauthcallback.myapp.com/
3. Registered Intent URI –
   intent:#Intent;action=com.myapp.OAUTH_C
   ALLBACK;S.code=1234512345;end
4. Registered MIME Type
Handling Callbacks – Invoked Browser




         Examples walkthrough…
Secure Token Handling

• TLS a must
• Tokens only shared with required parties
• Access tokens
  – Minimal scope
  – Typically short lived
  – (Transient) memory storage is common
• Refresh tokens
  – More sensitive due to long lifetimes
  – Stored in persistent memory
  – Application responsible for preventing leakage to
    other apps (e.g.: local prefs, key store, etc.)
Secure Token Handling (cont'd)




                                                                      The vulnerability was caused by Face.com storing
                                                                      Facebook and Twitter OAuth tokens – unique
                                                                      authentication keys – on its servers in an insecure way
                                                                      that made them accessible to anyone, Soltani said.



               http://www.macworld.com.au/news/face-com-flaw-could-have-allowed-facebook-twitter-hijacking-59587/




44    Copyright © 2011. Cloud Identity Summit. All Rights Reserved.
SSO Approaches

• External Browser
• Central App for Authentication & OAuth
  – Call out / Call back design required
  – e.g.: myauthapp://go?callclient=app1
• Account Manager
  – Built in framework available in Android
SUMMARY
Going Mobile with PingFederate

• Takeaways:
  – OAuth 2 can help deter a variety of API
    security issues, primarily improving user trust
  – Protocol itself is easy – challenge is
    integration with existing systems & policies
  – Client toolkits may help you – but ultimately
    understanding the spec and its intentions will
    help ensure it's implemented correctly
Going Mobile with
PingFederate and OAuth 2

Thanks!

Scott Tomilson
stomilson@pingidentity.com
Twitter: @scotttomilson

Contenu connexe

Tendances

Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
Igor Bossenko
 

Tendances (20)

OpenID Connect and Single Sign-On for Beginners
OpenID Connect and Single Sign-On for BeginnersOpenID Connect and Single Sign-On for Beginners
OpenID Connect and Single Sign-On for Beginners
 
CIS13: Introduction to OAuth 2.0
CIS13: Introduction to OAuth 2.0CIS13: Introduction to OAuth 2.0
CIS13: Introduction to OAuth 2.0
 
OAuth 2.0 and OpenId Connect
OAuth 2.0 and OpenId ConnectOAuth 2.0 and OpenId Connect
OAuth 2.0 and OpenId Connect
 
Mit 2014 introduction to open id connect and o-auth 2
Mit 2014   introduction to open id connect and o-auth 2Mit 2014   introduction to open id connect and o-auth 2
Mit 2014 introduction to open id connect and o-auth 2
 
Single-Page-Application & REST security
Single-Page-Application & REST securitySingle-Page-Application & REST security
Single-Page-Application & REST security
 
CIS14: Working with OAuth and OpenID Connect
CIS14: Working with OAuth and OpenID ConnectCIS14: Working with OAuth and OpenID Connect
CIS14: Working with OAuth and OpenID Connect
 
ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2ConFoo 2015 - Securing RESTful resources with OAuth2
ConFoo 2015 - Securing RESTful resources with OAuth2
 
An Authentication and Authorization Architecture for a Microservices World
An Authentication and Authorization Architecture for a Microservices WorldAn Authentication and Authorization Architecture for a Microservices World
An Authentication and Authorization Architecture for a Microservices World
 
Spring security oauth2
Spring security oauth2Spring security oauth2
Spring security oauth2
 
The Ultimate Guide to Mobile API Security
The Ultimate Guide to Mobile API SecurityThe Ultimate Guide to Mobile API Security
The Ultimate Guide to Mobile API Security
 
Introduction to OAuth2.0
Introduction to OAuth2.0Introduction to OAuth2.0
Introduction to OAuth2.0
 
Demystifying SAML 2.0,Oauth 2.0, OpenID Connect
Demystifying SAML 2.0,Oauth 2.0, OpenID ConnectDemystifying SAML 2.0,Oauth 2.0, OpenID Connect
Demystifying SAML 2.0,Oauth 2.0, OpenID Connect
 
REST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTsREST Service Authetication with TLS & JWTs
REST Service Authetication with TLS & JWTs
 
Best Practices in Building an API Security Ecosystem
Best Practices in Building an API Security EcosystemBest Practices in Building an API Security Ecosystem
Best Practices in Building an API Security Ecosystem
 
Presentation
PresentationPresentation
Presentation
 
OpenID Connect: The new standard for connecting to your Customers, Partners, ...
OpenID Connect: The new standard for connecting to your Customers, Partners, ...OpenID Connect: The new standard for connecting to your Customers, Partners, ...
OpenID Connect: The new standard for connecting to your Customers, Partners, ...
 
OpenID Connect Explained
OpenID Connect ExplainedOpenID Connect Explained
OpenID Connect Explained
 
JWT SSO Inbound Authenticator
JWT SSO Inbound AuthenticatorJWT SSO Inbound Authenticator
JWT SSO Inbound Authenticator
 
OpenID Connect 1.0 Explained
OpenID Connect 1.0 ExplainedOpenID Connect 1.0 Explained
OpenID Connect 1.0 Explained
 
Protecting web APIs with OAuth 2.0
Protecting web APIs with OAuth 2.0Protecting web APIs with OAuth 2.0
Protecting web APIs with OAuth 2.0
 

Similaire à CIS 2012 - Going Mobile with PingFederate and OAuth 2

Oauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 supportOauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 support
Gaurav Sharma
 
Globus Auth: A Research Identity and Access Management Platform
Globus Auth: A Research Identity and Access Management PlatformGlobus Auth: A Research Identity and Access Management Platform
Globus Auth: A Research Identity and Access Management Platform
Ian Foster
 

Similaire à CIS 2012 - Going Mobile with PingFederate and OAuth 2 (20)

Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares Oauth Nightmares Abstract OAuth Nightmares
Oauth Nightmares Abstract OAuth Nightmares
 
O auth2.0 guide
O auth2.0 guideO auth2.0 guide
O auth2.0 guide
 
How to Build an Indivo X Personal Health App
How to Build an Indivo X Personal Health AppHow to Build an Indivo X Personal Health App
How to Build an Indivo X Personal Health App
 
Getting Started with Globus for Developers
Getting Started with Globus for DevelopersGetting Started with Globus for Developers
Getting Started with Globus for Developers
 
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
CNIT 128: 6: Mobile services and mobile Web (part 1: Beginning Through OAuth)
 
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
2019 - Tech Talk DC - Token-based security for web applications using OAuth2 ...
 
2019 - Nova Code Camp - AuthZ fundamentals with ASP.NET Core
2019 - Nova Code Camp - AuthZ fundamentals with ASP.NET Core2019 - Nova Code Camp - AuthZ fundamentals with ASP.NET Core
2019 - Nova Code Camp - AuthZ fundamentals with ASP.NET Core
 
OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and Library
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWT
 
OAuth2 primer
OAuth2 primerOAuth2 primer
OAuth2 primer
 
Intro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID ConnectIntro to OAuth2 and OpenID Connect
Intro to OAuth2 and OpenID Connect
 
.NET Core, ASP.NET Core Course, Session 19
 .NET Core, ASP.NET Core Course, Session 19 .NET Core, ASP.NET Core Course, Session 19
.NET Core, ASP.NET Core Course, Session 19
 
Oauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 supportOauth2 and OWSM OAuth2 support
Oauth2 and OWSM OAuth2 support
 
Globus Auth: A Research Identity and Access Management Platform
Globus Auth: A Research Identity and Access Management PlatformGlobus Auth: A Research Identity and Access Management Platform
Globus Auth: A Research Identity and Access Management Platform
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWT
 
OAuth2 Best Practices in Native Apps
OAuth2 Best Practices in Native AppsOAuth2 Best Practices in Native Apps
OAuth2 Best Practices in Native Apps
 
Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0Protecting your APIs with Doorkeeper and OAuth 2.0
Protecting your APIs with Doorkeeper and OAuth 2.0
 
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Microservice security with spring security 5.1,Oauth 2.0 and open id connect Microservice security with spring security 5.1,Oauth 2.0 and open id connect
Microservice security with spring security 5.1,Oauth 2.0 and open id connect
 
Introduction to the Globus Platform for Developers
Introduction to the Globus Platform for DevelopersIntroduction to the Globus Platform for Developers
Introduction to the Globus Platform for Developers
 
Rest API Security - A quick understanding of Rest API Security
Rest API Security - A quick understanding of Rest API SecurityRest API Security - A quick understanding of Rest API Security
Rest API Security - A quick understanding of Rest API Security
 

Dernier

Dernier (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

CIS 2012 - Going Mobile with PingFederate and OAuth 2

  • 1. Going Mobile with PingFederate and OAuth 2 Scott Tomilson Technical Product Manager Ping Identity Copyright © 2012. Cloud Identity Summit. All Rights Reserved.
  • 3. About me … "Who the heck is this guy? And why should I listen?"
  • 4. About me … Scott Tomilson • "Inside" Technical Product Manager for PingFederate • Based in Vancouver, Canada • Spent majority of career in Japan & Australia • 12 years in Security / IdM • Engineer, Consultant, Trainer • CISSP photo kindly stolen from Brian D. Campbell
  • 5. Going Mobile - PingFederate and OAuth 2 • Agenda – OAuth 2 & You – "Hands-on" with the OAuth 2 Playground – Break (yay!) – Even more "Hands-on" work – Mobile Integration dive: iOS & Android – Wrap-up
  • 6. OAUTH 2 & YOU
  • 7. 5 reasons to love OAuth 2 (for Mobile) ? 1. You've got REST API's, you want a standard way to secure them 2. Your API's / applications involve sensitive resources that either your organization or end users want to control access to 3. Your API will be available to partner apps, but you still control user authentication 4. You need revocation capabilities 5. You / your company paid for this workshop – so, why the heck not!
  • 8. Speaking OAuth 2 (i.e.: Terminology) "Actors" • Client - Wants access to a resource protected by a Resource Server and interacts with an Authorization Server to obtain tokens. • Resource Server (RS) - Hosts and protects resources and makes them available to properly authenticated and authorized clients. • Authorization Server (AS) - Issues access and refresh tokens to clients on behalf of RS's.
  • 9. OAuth 2 Terminology (cont'd) Protocol Terms • Access token (AT) - Allows clients to authenticate to an RS and claim authorizations for accessing particular resources. Expires based on time (typically minutes). • Refresh token (RT) - Allows clients to obtain a fresh access token without re-obtaining authorization from the resource owner. Expires based on user revocation or time (typically days). • Authorization Code – One time code issued by an AS to be exchanged for an AT. • Scopes – A permission (or set of permissions) defined and agreed upon by the Client, RS and AS.
  • 10. OAuth 2 Terminology (cont'd again) Protocol Terms (cont'd) • Grant Types - An authorization grant is a credential representing the resource owner's authorization (to access its protected resources) used by the client to obtain an access token. Grant types dictate how the authorization grant is performed (and thus how the token is released). Examples: • Authorization Code • Implicit • Resource Owner Password Credentials
  • 11. A "TYPICAL" MOBILE OAUTH 2 DEMO
  • 12. Authorization Code Grant 1.) User accesses Native Mobile Application and requests action. Action requires user authentication 2 and/or authorization to the Resource Server (RS). 2.) Native Application launches the device's browser 3 and requests the Authorization Server's (AS) Authorization Server authorization endpoint 4 (PingFederate) (https://<pf>/as/authorization.oauth2). Request query string includes the OAuth client ID, request type and requested scopes. 3.) User authenticates to Authorization Server (AS) via IdP Adapter, or IdP Connection. After authentication user sees confirmation page with requested scopes and clicks "Approve". 5 4.) AS redirects user back to the Native Mobile Application via a custom registered scheme Browser (protocol) that the application registered, and includes an authorization code in the query string Resource Server (e.g.: partnerapp://callback?code=xxxxx). Native Mobile (REST API endpoint) 5.) Native Mobile App resolves authorization code to Application a token (access token [and refresh token]) via REST API call to the AS token endpoint (https://<pf>/as/token.oauth2). 1
  • 13. Token [ Mobile Application Integration – Redirection Flow Native Refresh & ] Usage Token Refresh & Usage 1.) User accesses Native Mobile Application and [3] requests action. Action requires user authentication and/or authorization to the Resource Server (RS). 2.) Native Mobile Application checks if user has a valid (non-expired) access token. If none available Authorization Server 5 (and a refresh token is available) a request to the (PingFederate) Authorization Server (AS) token endpoint (https://<pf>/as/token.oauth2) to obtain a new one. Browser 3.) AS looks up refresh token in its persistent grant storage, and if valid, issues a new access token (and possibly refresh token). Native Mobile [2] 4.) Native Mobile Application inserts the OAuth access token in an Authorization HTTP header Application (Bearer type), and makes the REST API call to the RS. 5.) RS validates incoming access token with AS using the token endpoint 4 (https://</pf>/as/token.oauth2) with a PingFederate validation grant type. AS returns 1 Resource Server validation results including user attributes. (REST API endpoint)
  • 14. Authorization Code Grant Mobile example demo… 14 Copyright © 2011. Cloud Identity Summit. All Rights Reserved.
  • 15. Authorization Code Grant Protocol Details Request: https://as.pingidentity.com/as/authorization.oauth2? client_id=my_app_id&response_type=code ( Login … Authorize ) Callback Response: HTTP/1.1 302 Found Location: my_app://app.myapp.com/oauth?code=SplxlOBeZQQYbYS6WxSbIA
  • 16. Authorization Code Grant Protocol Details (cont'd) Request: POST /as/token.oauth2 HTTP/1.1 Host: as.pingidentity.com Content-Type: application/x-www-form-urlencoded;charset=UTF-8 grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA Response: HTTP/1.1 200 OK Content-Type: application/json;charset=UTF-8 Cache-Control: no-store Pragma: no-cache {"token_type":"Bearer","expires_in":60, "access_token":"PeRTSD9RQrbiuoaHVP xV41MzW1qS"}
  • 17. Token Usage Protocol Details GET /some/api/call HTTP/1.1 Host: rs.myapp.com Authorization: Bearer PeRTSD9RQrbiuoaHVPxV41MzW1qS
  • 18. Native Mobile Application Integration Getting a Token (cont’d) • Open browser to authorization endpoint sample code: - (IBAction)doAction:(id)sender { NSLog(@"About to open Safari to OAuth AS Authorization Endpoint..."); // In this example, use a named IDP connection for user authentication NSString* launchUrl = @"https://as.pingidentity.com/as/authorization.oauth2?client_id=mobileclient1&respons e_type=code&idp=partner:entity:id"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString: launchUrl]]; }
  • 19. Native Mobile Application Integration Getting a Token (cont’d) • Registering a custom URI scheme in iOS:
  • 20. Native Mobile Application Integration Getting a Token (cont’d) • Handling parameters – sample code: // Parse of URL query string complete if (error != nil) { // Show error message to user } else { NSString *code = [qsParms objectForKey:@"code"]; // Form HTTP POST to resolve JSON structure NSString *post = [NSString stringWithFormat:@"grant_type=authorization_code&code=%@", code]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
  • 21. Native Mobile Application Integration Getting a Token (cont’d) • Handling parameters – sample code (cont'd): NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:@"https://as.idp.com/as/token.oauth2"]]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self]; if (conn) { receivedData = [[NSMutableData data] retain]; } }
  • 22. Native Mobile Application Integration Getting a Token (cont’d) • Handling parameters – sample code (cont'd): - (void)connectionDidFinishLoading:(NSURLConnection *)connection { // json-framework library: https://github.com/stig/json-framework/ SBJsonParser *jsonParser = [[SBJsonParser alloc] init]; NSString *aStr = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding]; NSString *accessToken = nil; NSString *refreshToken = nil; id object = [jsonParser objectWithString:aStr]; if (object) { NSLog(@"JSON parsed successfully."); if ([object isKindOfClass:[NSDictionary class]]) { NSDictionary *nsDict = (NSDictionary*)object; accessToken = [nsDict objectForKey:@"access_token"]; refreshToken = [nsDict objectForKey:@"refresh_token"]; }
  • 23. Native Mobile Application Integration Using a Token (cont'd) • Sample code: // Form the Bearer token Authorization header NSString *authzHeader = [NSString stringWithFormat:@"Bearer %@", accessToken]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:@"https://rs.idp.com/msg/api"]]; [request setValue:authzHeader forHTTPHeaderField:@"Authorization"]; NSLog(@"Initiating URL connection to RS with access_token..."); NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:request delegate:self];
  • 24. GETTING TO KNOW GRANT TYPES
  • 25. Grant Types for Mobile • "Using a Token" is easy (for Bearer) • "Getting a Token" requires decisions • Grant Types most applicable to mobile: – Authorization Code – Implicit – Resource Owner Password Credentials
  • 26. Grant Types for Mobile Grant Type Authentication Authz Refresh Tokens Types of Apps Step Support? Authorization Browser based ✔ ✔ • 3rd Party App Code • Trusted App using Web based Authn Implicit Browser based ✔ ✖ • As above, but lives in browser; e.g.: JS app Resource Application ✖ ✔ • Trusted App, Owner using only Password username/pass Credentials word Authn
  • 27. RO Password Credentials Grant Type Mobile example demo… 27 Copyright © 2011. Cloud Identity Summit. All Rights Reserved.
  • 28. Comparison of Grant Types & Models Authorization Code ( Resource Owner Embedded browser) Credentials • No need to leave app context • Password shared with 3rd party • Application owns login UI • Enables SSO • Enables strong authn • AS owns login UI • Visual trust cues (SSL lock) • Authentication can leverage stored passwords • Authentication can leverage existing sessions Authorization Code ( Separate browser ) 28
  • 29. One more thing … Client Authentication • So, yeah - what about Client Authn? • Possible additional security requirement before grant • Limited use for mobile / client side apps… 10.1. Client Authentication . . . The authorization server MUST NOT issue client passwords or other client credentials to native application or user-agent-based application clients for the purpose of client authentication. The authorization server MAY issue a client password or other credentials for a specific installation of a native application client on a specific device. . . . http://tools.ietf.org/html/draft-ietf-oauth-v2-30#section-10.1
  • 30. Going Mobile - PingFederate and OAuth 2 • Agenda – OAuth 2 & You – "Hands-on" with the OAuth 2 Playground – Break – Even more "Hands-on" work – Mobile Integration dive: iOS & Android – Wrap-up
  • 31. "HANDS-ON" WITH THE OAUTH 2.0 PLAYGROUND
  • 32. PingFederate OAuth 2 Playground • Setup hands-on activity starts now! • On the USB thumb drives: – JDK 1.6 (for Windows - 32 and 64 bit) – PingFederate 6.8 (& trial license) – OAuth 2 Playground – LabReadme.pdf • Follow PDF instruction to set up the lab
  • 33. Going Mobile with PingFederate and OAuth 2 Break Back @ 2:45PM sharp!
  • 34. Going Mobile - PingFederate and OAuth 2 • Agenda – OAuth 2 & You – "Hands-on" with the OAuth 2 Playground – Break – Even more "Hands-on" work – Mobile Integration dive: iOS & Android – Wrap-up
  • 35. Hands-on Playground Fun 1. Enable Refresh Token grant type and test it. As the end user, revoke the grant. 2. Enable "Bypass" of Authorization for the Authorization Code use case. Test it. 3. Add a callback Redirect URL scheme to be myapp://. Test it – using browser trace. 4. Define additional users for Resource Owner Password Credentials Grant Type, and new AT user attribute for Department. Test it.
  • 37. Mobile Integration Dive Let's talk about the tricky bits: • Integration Approaches • Combining Native Apps and Browsers – Embedding vs. Invoking the Browser – Handling callbacks • Secure Token Handling • SSO Approaches
  • 38. OAuth Mobile Integration Integration Approaches • DIY OAuth integration – Effort level is small(-ish). Examples are used in this presentation. Requires: • Launching the browser (externally or embedded) • Detecting callback from the browser • JSON response parsing • Secure token handling • OAuth Client Library – Provides the above functionality with a higher level of abstraction. E.g.: • Google Toolbox for Mac – OAuth 2 Controllers: http://code.google.com/p/gtm-oauth2/ 38
  • 39. Embedding vs. Invoking the Browser Embedding Invoking (Android WebView / iOS UIWebView) (External Browser) Pros: Pros: • Seamless user experience • Full, trusted browser UI • More options for callback • Share existing authn sessions handling (e.g.: cookies, title) (WAM SSO) • Better for some MITM attacks Cons: Cons: • May look suspect to savvy users • Different default browsers – • Doesn't share cookies custom scheme URI's may not be handled (Opera on Android)
  • 40. Handling Callbacks – Embedded Browser Ways a native app could get the callback (authorization code): 1. Cookies – Name of the cookie is agreed upon 2. Window Title – Code is in the HTML <title> tag, which can be read by native app. • May be vulnerable to leaks if the website has cross-site scripting bugs.
  • 41. Handling Callbacks – Invoked Browser Ways a native app could get the callback (authorization code): 1. Custom URI Scheme – myapp:// 2. Registered Intent for Scheme/Host – https://oauthcallback.myapp.com/ 3. Registered Intent URI – intent:#Intent;action=com.myapp.OAUTH_C ALLBACK;S.code=1234512345;end 4. Registered MIME Type
  • 42. Handling Callbacks – Invoked Browser Examples walkthrough…
  • 43. Secure Token Handling • TLS a must • Tokens only shared with required parties • Access tokens – Minimal scope – Typically short lived – (Transient) memory storage is common • Refresh tokens – More sensitive due to long lifetimes – Stored in persistent memory – Application responsible for preventing leakage to other apps (e.g.: local prefs, key store, etc.)
  • 44. Secure Token Handling (cont'd) The vulnerability was caused by Face.com storing Facebook and Twitter OAuth tokens – unique authentication keys – on its servers in an insecure way that made them accessible to anyone, Soltani said. http://www.macworld.com.au/news/face-com-flaw-could-have-allowed-facebook-twitter-hijacking-59587/ 44 Copyright © 2011. Cloud Identity Summit. All Rights Reserved.
  • 45. SSO Approaches • External Browser • Central App for Authentication & OAuth – Call out / Call back design required – e.g.: myauthapp://go?callclient=app1 • Account Manager – Built in framework available in Android
  • 47. Going Mobile with PingFederate • Takeaways: – OAuth 2 can help deter a variety of API security issues, primarily improving user trust – Protocol itself is easy – challenge is integration with existing systems & policies – Client toolkits may help you – but ultimately understanding the spec and its intentions will help ensure it's implemented correctly
  • 48. Going Mobile with PingFederate and OAuth 2 Thanks! Scott Tomilson stomilson@pingidentity.com Twitter: @scotttomilson