SlideShare una empresa de Scribd logo
1 de 77
OAuth
Nurulazrad Murad @azrad

     3rd Nov 2012
look for “primus core”
topics
topics


what is OAuth?
topics


what is OAuth?
writing a Consumer in PHP
traditionally, this is how we do it
onn ect!
               c

user: azrad
pass: secret
onn ect!
               c

user: azrad
pass: secret


               user: azrad
               pass: secret
onn ect!
               c

user: azrad
pass: secret


               user: azrad
               pass: secret




user: azrad
you reveal your username
      and password
who using it?
who using it?
the love triangle
end user




                              consumer application
service provider
end user




                              consumer application
service provider
OAuth goal...
 oAuth is...
OAuth goal...
         oAuth is...


Authentication
•   must logged-in to access the website/application
OAuth goal...
         oAuth is...


Authentication
•   must logged-in to access the website/application

Token-based authentication
•   logged-in user has unique token per application
OAuth goal...
oAuth goal...
OAuth goal...
        oAuth goal...

be simple
•   standard for website API authentication
•   consistent for developers
•   easy for users to understand *
OAuth goal...
           oAuth goal...

  be simple
   •   standard for website API authentication
   •   consistent for developers
   •   easy for users to understand *




* this is hard
OAuth goal...
oAuth goal...
OAuth goal...
         oAuth goal...


be secure
•   secure for users
•   easy to implement security features for developers
•   balance security with ease of use
OAuth goal...
oAuth goal...
OAuth goal...
         oAuth goal...

be open
•   any website can implement OAuth
•   any developer can user OAuth
•   open source client libraries
•   published technical specifications
OAuth goal...
OAuth goal...

be flexible
•   don’t need username and password
•   authentication method agnostic
•   can use OpenID (or not)
•   whatever works best for the web service
•   developers don’t need to handle auth
what the user end sees?
  example from Primus Core Helang Api
how does OAuth works?
register a consumer app
register a consumer app

 provide service provider with data about your
 application (name, url...)
register a consumer app

 provide service provider with data about your
 application (name, url...)
 service provider assigns consumer a
 consumer key and consumer secret
register a consumer app

 provide service provider with data about your
 application (name, url...)
 service provider assigns consumer a
 consumer key and consumer secret
 service provider gives documentation of
 authorization URLs and methods
user   consumer   service provider
user             consumer   service provider

 click connect
user             consumer             service provider

 click connect        request token
user             consumer                         service provider

 click connect        request token



                             request token, request secret
user                               consumer                         service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider
user                               consumer                         service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider


 user authorise request token
user                               consumer                           service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider


 user authorise request token


                                                        redirect with verifier
user                               consumer                           service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider


 user authorise request token


                                                        redirect with verifier

   notifies app with verifier
user                               consumer                           service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider


 user authorise request token


                                                        redirect with verifier

   notifies app with verifier
                                       request token → access token
user                               consumer                           service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider


 user authorise request token


                                                        redirect with verifier

   notifies app with verifier
                                       request token → access token


                                               access token, access secret
user                               consumer                           service provider

 click connect                          request token



                                               request token, request secret
       redirect user to provider


 user authorise request token


                                                        redirect with verifier

   notifies app with verifier
                                       request token → access token


                                               access token, access secret
                                        request on user’s behalf
the codes
https://github.com/myelin/fireeagle-php-lib
request token + secret from FE
request token + secret from FE
 if (@$_GET['f'] == 'start') {
   // get a request token + secret from FE and redirect to the authorization
page
   // START step 1
   $fe = new FireEagle($fe_key, $fe_secret);
   $tok = $fe->getRequestToken($fe_callback);
   if (!isset($tok['oauth_token'])
       || !is_string($tok['oauth_token'])
       || !isset($tok['oauth_token_secret'])
       || !is_string($tok['oauth_token_secret'])) {
     echo "ERROR! FireEagle::getRequestToken() returned an invalid
response. Giving up.";
     exit;
   }
   $_SESSION['auth_state'] = "start";
   $_SESSION['request_token'] = $token = $tok['oauth_token'];
   $_SESSION['request_secret'] = $tok['oauth_token_secret'];
   header("Location: ".$fe->getAuthorizeURL($token));
   // END step 1
} else if (@$_GET['f'] == 'callback') {
  // the user has authorized us at FE, so now we can pick up our access token + secret
  // START step 2
  if (@$_SESSION['auth_state'] != "start") {
    echo "Out of sequence.";
    exit;
  }
  if ($_GET['oauth_token'] != $_SESSION['request_token']) {
    echo "Token mismatch.";
    exit;
  }
      if ((FireEagle::$FE_OAUTH_VERSION == OAUTH_VERSION_10A)
          && !isset($_GET['oauth_verifier'])) {
          echo "OAuth protocol error. No verifier in response.";
          exit;
      }

 $fe = new FireEagle($fe_key, $fe_secret, $_SESSION['request_token'], $_SESSION['request_secret']);
 $tok = $fe->getAccessToken($_GET['oauth_verifier']);
 if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token'])
     || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) {
   error_log("Bad token from FireEagle::getAccessToken(): ".var_export($tok, TRUE));
   echo "ERROR! FireEagle::getAccessToken() returned an invalid response. Giving up.";
   exit;
 }

 $_SESSION['access_token'] = $tok['oauth_token'];
 $_SESSION['access_secret'] = $tok['oauth_token_secret'];
 $_SESSION['auth_state'] = "done";
 header("Location: ".$_SERVER['SCRIPT_NAME']);
                                                                             get access
 // END step 2
                                                                             token + secret
// we have our access token + secret, so now we can actually *use* the api
  // START step 3
  $fe = new FireEagle($fe_key, $fe_secret, $_SESSION['access_token'], $_SESSION['access_secret']);

  $loc = $fe->user(); // equivalent to $fe->call("user")
  ?><h2>Where you are<?php if ($loc->user->best_guess) echo ": ".htmlspecialchars($loc->user->best_guess-
>name) ?></h2><?php
  if (empty($loc->user->location_hierarchy)) {
    ?><p>Fire Eagle doesn't know where you are yet.</p><?php // '
  } else {
    foreach ($loc->user->location_hierarchy as $location) {
      switch ($location->geotype) {
      case 'point':
        $locinfo = "[".$location->latitude.", ".$location->longitude."]";
        break;
      case 'box':
        $locinfo = "[[".$location->bbox[0][1].", ".$location->bbox[0][0]."], ["
          .$location->bbox[1][1].", ".$location->bbox[1][0]."]]";
        break;
      default:
        $locinfo = "[unknown]";
        break;
      }
      if ($location->best_guess) $locinfo .= " BEST GUESS";
      print "<h3>".htmlspecialchars($location->level_name).": ".htmlspecialchars($location->name)." $locinfo</h3>";
      print "<ul>";
      // turn location object into array, with sorted keys
      $l = array(); foreach ($location as $k => $v) $l[$k] = $v; ksort($l);
      foreach ($l as $k => $v) {
        print "<li>".htmlspecialchars($k).": <b>".htmlspecialchars(var_export($v, TRUE))."</b></li>";
      }
      print "</ul>";
    }
  }
demo
where is info passed?
where is info passed?


http authorisation header
where is info passed?


http authorisation header
http post request body (form params)
where is info passed?


http authorisation header
http post request body (form params)
url query string parameters
security
security

tokens: aren’t passing username/password
security

tokens: aren’t passing username/password
timestamp and nonce: very unique requests
security

tokens: aren’t passing username/password
timestamp and nonce: very unique requests
signature: encrypted parameters help service
provider recognise consumer
security

tokens: aren’t passing username/password
timestamp and nonce: very unique requests
signature: encrypted parameters help service
provider recognise consumer
signature methods: HMAC-SHA1, RSA-SHA1,
plaintext over a secure channel (SSL)
current status of OAuth
current status of OAuth

 oauth.net
current status of OAuth

 oauth.net
 Auth 1.0 protocol (RFC 5849)
current status of OAuth

 oauth.net
 Auth 1.0 protocol (RFC 5849)
 OAuth 2.0 working draft
current status of OAuth

 oauth.net
 Auth 1.0 protocol (RFC 5849)
 OAuth 2.0 working draft
 several libraries for consumers and service
 providers
links

OAuth spec          http://oauth.net
PECL Extension      http://pecl.php.net/oauth
Fireeagle           http://fireeagle.yahoo.net
FE library (PHP)
 https://github.com/myelin/fireeagle-php-lib
thanks!

twitter: @azrad
tumblr: nurulazrad.tumblr.com
works at: www.primuscore.com
credit

OAuth - Open API Authentication by
leahculver on Dec 01, 2007
Implementing OAuth with PHP by Lorna
Mitchell on May 17, 2011
Using OAuth with PHP by David Ingram on
Nov 04, 2010

Más contenido relacionado

La actualidad más candente

OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - IntroductionKnoldus Inc.
 
OAuth for your API - The Big Picture
OAuth for your API - The Big PictureOAuth for your API - The Big Picture
OAuth for your API - The Big PictureApigee | Google Cloud
 
An Introduction to OAuth 2
An Introduction to OAuth 2An Introduction to OAuth 2
An Introduction to OAuth 2Aaron Parecki
 
OAuth big picture
OAuth big pictureOAuth big picture
OAuth big pictureMin Li
 
An Introduction to OAuth2
An Introduction to OAuth2An Introduction to OAuth2
An Introduction to OAuth2Aaron Parecki
 
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013Aaron Parecki
 
Security for oauth 2.0 - @topavankumarj
Security for oauth 2.0 - @topavankumarjSecurity for oauth 2.0 - @topavankumarj
Security for oauth 2.0 - @topavankumarjPavan Kumar J
 
The Current State of OAuth 2
The Current State of OAuth 2The Current State of OAuth 2
The Current State of OAuth 2Aaron Parecki
 
OAuth2 Authentication
OAuth2 AuthenticationOAuth2 Authentication
OAuth2 AuthenticationIsmael Costa
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTGaurav Roy
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectJonathan LeBlanc
 
OAuth Hacks A gentle introduction to OAuth 2 and Apache Oltu
OAuth Hacks A gentle introduction to OAuth 2 and Apache OltuOAuth Hacks A gentle introduction to OAuth 2 and Apache Oltu
OAuth Hacks A gentle introduction to OAuth 2 and Apache OltuAntonio Sanso
 
Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Alvaro Sanchez-Mariscal
 
Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015Alvaro Sanchez-Mariscal
 
OAuth 2 at Webvisions
OAuth 2 at WebvisionsOAuth 2 at Webvisions
OAuth 2 at WebvisionsAaron Parecki
 

La actualidad más candente (20)

OAuth2 - Introduction
OAuth2 - IntroductionOAuth2 - Introduction
OAuth2 - Introduction
 
OAuth for your API - The Big Picture
OAuth for your API - The Big PictureOAuth for your API - The Big Picture
OAuth for your API - The Big Picture
 
An Introduction to OAuth 2
An Introduction to OAuth 2An Introduction to OAuth 2
An Introduction to OAuth 2
 
OAuth big picture
OAuth big pictureOAuth big picture
OAuth big picture
 
OAuth 2
OAuth 2OAuth 2
OAuth 2
 
OAuth 2.0
OAuth 2.0OAuth 2.0
OAuth 2.0
 
An Introduction to OAuth2
An Introduction to OAuth2An Introduction to OAuth2
An Introduction to OAuth2
 
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
Using ArcGIS with OAuth 2.0 - Esri DevSummit Dubai 2013
 
Demystifying OAuth 2.0
Demystifying OAuth 2.0Demystifying OAuth 2.0
Demystifying OAuth 2.0
 
Security for oauth 2.0 - @topavankumarj
Security for oauth 2.0 - @topavankumarjSecurity for oauth 2.0 - @topavankumarj
Security for oauth 2.0 - @topavankumarj
 
The Current State of OAuth 2
The Current State of OAuth 2The Current State of OAuth 2
The Current State of OAuth 2
 
OAuth2 Authentication
OAuth2 AuthenticationOAuth2 Authentication
OAuth2 Authentication
 
Stateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWTStateless Auth using OAuth2 & JWT
Stateless Auth using OAuth2 & JWT
 
Securing RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID ConnectSecuring RESTful APIs using OAuth 2 and OpenID Connect
Securing RESTful APIs using OAuth 2 and OpenID Connect
 
OAuth Hacks A gentle introduction to OAuth 2 and Apache Oltu
OAuth Hacks A gentle introduction to OAuth 2 and Apache OltuOAuth Hacks A gentle introduction to OAuth 2 and Apache Oltu
OAuth Hacks A gentle introduction to OAuth 2 and Apache Oltu
 
Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015Stateless authentication for microservices - GR8Conf 2015
Stateless authentication for microservices - GR8Conf 2015
 
OAuth2 + API Security
OAuth2 + API SecurityOAuth2 + API Security
OAuth2 + API Security
 
Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015Stateless authentication for microservices - Greach 2015
Stateless authentication for microservices - Greach 2015
 
OAuth
OAuthOAuth
OAuth
 
OAuth 2 at Webvisions
OAuth 2 at WebvisionsOAuth 2 at Webvisions
OAuth 2 at Webvisions
 

Similar a OAuth using PHP5

OAuth: demystified (hopefully)
OAuth: demystified (hopefully)OAuth: demystified (hopefully)
OAuth: demystified (hopefully)Matt Gifford
 
Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Kai Hofstetter
 
OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootGeert Pante
 
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...Brian Campbell
 
JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020Matt Raible
 
Spring4 security oauth2
Spring4 security oauth2Spring4 security oauth2
Spring4 security oauth2axykim00
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTMobiliya
 
The Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itThe Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itBastian Hofmann
 
1000 ways to die in mobile oauth
1000 ways to die in mobile oauth1000 ways to die in mobile oauth
1000 ways to die in mobile oauthPriyanka Aash
 
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 AppBen Adida
 
Learn with WSO2 - API Security
Learn with WSO2 - API Security Learn with WSO2 - API Security
Learn with WSO2 - API Security WSO2
 
OAuth 2.0 Misconceptions
OAuth 2.0 MisconceptionsOAuth 2.0 Misconceptions
OAuth 2.0 MisconceptionsCory Forsyth
 
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020Matt Raible
 
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 EcosystemPrabath Siriwardena
 
What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018Matt Raible
 
OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and LibraryKenji Otsuka
 
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 ConnectCloudIDSummit
 

Similar a OAuth using PHP5 (20)

OAuth: demystified (hopefully)
OAuth: demystified (hopefully)OAuth: demystified (hopefully)
OAuth: demystified (hopefully)
 
Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0Securing APIs with OAuth 2.0
Securing APIs with OAuth 2.0
 
OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring Boot
 
O auth2.0 guide
O auth2.0 guideO auth2.0 guide
O auth2.0 guide
 
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
OAuth 2.0 and Mobile Devices: Is that a token in your phone in your pocket or...
 
JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020JHipster and Okta - JHipster Virtual Meetup December 2020
JHipster and Okta - JHipster Virtual Meetup December 2020
 
TLDR - OAuth
TLDR - OAuthTLDR - OAuth
TLDR - OAuth
 
OAuth: Trust Issues
OAuth: Trust IssuesOAuth: Trust Issues
OAuth: Trust Issues
 
Spring4 security oauth2
Spring4 security oauth2Spring4 security oauth2
Spring4 security oauth2
 
Stateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWTStateless Auth using OAUTH2 & JWT
Stateless Auth using OAUTH2 & JWT
 
The Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itThe Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve it
 
1000 ways to die in mobile oauth
1000 ways to die in mobile oauth1000 ways to die in mobile oauth
1000 ways to die in mobile oauth
 
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
 
Learn with WSO2 - API Security
Learn with WSO2 - API Security Learn with WSO2 - API Security
Learn with WSO2 - API Security
 
OAuth 2.0 Misconceptions
OAuth 2.0 MisconceptionsOAuth 2.0 Misconceptions
OAuth 2.0 Misconceptions
 
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
What the Heck is OAuth and OIDC - Denver Developer Identity Workshop 2020
 
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
 
What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018What the Heck is OAuth and OIDC - UberConf 2018
What the Heck is OAuth and OIDC - UberConf 2018
 
OAuth 2.0 and Library
OAuth 2.0 and LibraryOAuth 2.0 and Library
OAuth 2.0 and Library
 
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
 

Último

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 

Último (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 

OAuth using PHP5

  • 2.
  • 6. topics what is OAuth? writing a Consumer in PHP
  • 7. traditionally, this is how we do it
  • 8.
  • 9. onn ect! c user: azrad pass: secret
  • 10. onn ect! c user: azrad pass: secret user: azrad pass: secret
  • 11. onn ect! c user: azrad pass: secret user: azrad pass: secret user: azrad
  • 12.
  • 13. you reveal your username and password
  • 14.
  • 18. end user consumer application service provider
  • 19. end user consumer application service provider
  • 21. OAuth goal... oAuth is... Authentication • must logged-in to access the website/application
  • 22. OAuth goal... oAuth is... Authentication • must logged-in to access the website/application Token-based authentication • logged-in user has unique token per application
  • 24. OAuth goal... oAuth goal... be simple • standard for website API authentication • consistent for developers • easy for users to understand *
  • 25. OAuth goal... oAuth goal... be simple • standard for website API authentication • consistent for developers • easy for users to understand * * this is hard
  • 27. OAuth goal... oAuth goal... be secure • secure for users • easy to implement security features for developers • balance security with ease of use
  • 29. OAuth goal... oAuth goal... be open • any website can implement OAuth • any developer can user OAuth • open source client libraries • published technical specifications
  • 31. OAuth goal... be flexible • don’t need username and password • authentication method agnostic • can use OpenID (or not) • whatever works best for the web service • developers don’t need to handle auth
  • 32. what the user end sees? example from Primus Core Helang Api
  • 33.
  • 34.
  • 35. how does OAuth works?
  • 37. register a consumer app provide service provider with data about your application (name, url...)
  • 38. register a consumer app provide service provider with data about your application (name, url...) service provider assigns consumer a consumer key and consumer secret
  • 39. register a consumer app provide service provider with data about your application (name, url...) service provider assigns consumer a consumer key and consumer secret service provider gives documentation of authorization URLs and methods
  • 40. user consumer service provider
  • 41. user consumer service provider click connect
  • 42. user consumer service provider click connect request token
  • 43. user consumer service provider click connect request token request token, request secret
  • 44. user consumer service provider click connect request token request token, request secret redirect user to provider
  • 45. user consumer service provider click connect request token request token, request secret redirect user to provider user authorise request token
  • 46. user consumer service provider click connect request token request token, request secret redirect user to provider user authorise request token redirect with verifier
  • 47. user consumer service provider click connect request token request token, request secret redirect user to provider user authorise request token redirect with verifier notifies app with verifier
  • 48. user consumer service provider click connect request token request token, request secret redirect user to provider user authorise request token redirect with verifier notifies app with verifier request token → access token
  • 49. user consumer service provider click connect request token request token, request secret redirect user to provider user authorise request token redirect with verifier notifies app with verifier request token → access token access token, access secret
  • 50. user consumer service provider click connect request token request token, request secret redirect user to provider user authorise request token redirect with verifier notifies app with verifier request token → access token access token, access secret request on user’s behalf
  • 53. request token + secret from FE
  • 54. request token + secret from FE if (@$_GET['f'] == 'start') { // get a request token + secret from FE and redirect to the authorization page // START step 1 $fe = new FireEagle($fe_key, $fe_secret); $tok = $fe->getRequestToken($fe_callback); if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) { echo "ERROR! FireEagle::getRequestToken() returned an invalid response. Giving up."; exit; } $_SESSION['auth_state'] = "start"; $_SESSION['request_token'] = $token = $tok['oauth_token']; $_SESSION['request_secret'] = $tok['oauth_token_secret']; header("Location: ".$fe->getAuthorizeURL($token)); // END step 1
  • 55.
  • 56.
  • 57. } else if (@$_GET['f'] == 'callback') { // the user has authorized us at FE, so now we can pick up our access token + secret // START step 2 if (@$_SESSION['auth_state'] != "start") { echo "Out of sequence."; exit; } if ($_GET['oauth_token'] != $_SESSION['request_token']) { echo "Token mismatch."; exit; } if ((FireEagle::$FE_OAUTH_VERSION == OAUTH_VERSION_10A) && !isset($_GET['oauth_verifier'])) { echo "OAuth protocol error. No verifier in response."; exit; } $fe = new FireEagle($fe_key, $fe_secret, $_SESSION['request_token'], $_SESSION['request_secret']); $tok = $fe->getAccessToken($_GET['oauth_verifier']); if (!isset($tok['oauth_token']) || !is_string($tok['oauth_token']) || !isset($tok['oauth_token_secret']) || !is_string($tok['oauth_token_secret'])) { error_log("Bad token from FireEagle::getAccessToken(): ".var_export($tok, TRUE)); echo "ERROR! FireEagle::getAccessToken() returned an invalid response. Giving up."; exit; } $_SESSION['access_token'] = $tok['oauth_token']; $_SESSION['access_secret'] = $tok['oauth_token_secret']; $_SESSION['auth_state'] = "done"; header("Location: ".$_SERVER['SCRIPT_NAME']); get access // END step 2 token + secret
  • 58.
  • 59. // we have our access token + secret, so now we can actually *use* the api // START step 3 $fe = new FireEagle($fe_key, $fe_secret, $_SESSION['access_token'], $_SESSION['access_secret']); $loc = $fe->user(); // equivalent to $fe->call("user") ?><h2>Where you are<?php if ($loc->user->best_guess) echo ": ".htmlspecialchars($loc->user->best_guess- >name) ?></h2><?php if (empty($loc->user->location_hierarchy)) { ?><p>Fire Eagle doesn't know where you are yet.</p><?php // ' } else { foreach ($loc->user->location_hierarchy as $location) { switch ($location->geotype) { case 'point': $locinfo = "[".$location->latitude.", ".$location->longitude."]"; break; case 'box': $locinfo = "[[".$location->bbox[0][1].", ".$location->bbox[0][0]."], [" .$location->bbox[1][1].", ".$location->bbox[1][0]."]]"; break; default: $locinfo = "[unknown]"; break; } if ($location->best_guess) $locinfo .= " BEST GUESS"; print "<h3>".htmlspecialchars($location->level_name).": ".htmlspecialchars($location->name)." $locinfo</h3>"; print "<ul>"; // turn location object into array, with sorted keys $l = array(); foreach ($location as $k => $v) $l[$k] = $v; ksort($l); foreach ($l as $k => $v) { print "<li>".htmlspecialchars($k).": <b>".htmlspecialchars(var_export($v, TRUE))."</b></li>"; } print "</ul>"; } }
  • 60. demo
  • 61. where is info passed?
  • 62. where is info passed? http authorisation header
  • 63. where is info passed? http authorisation header http post request body (form params)
  • 64. where is info passed? http authorisation header http post request body (form params) url query string parameters
  • 67. security tokens: aren’t passing username/password timestamp and nonce: very unique requests
  • 68. security tokens: aren’t passing username/password timestamp and nonce: very unique requests signature: encrypted parameters help service provider recognise consumer
  • 69. security tokens: aren’t passing username/password timestamp and nonce: very unique requests signature: encrypted parameters help service provider recognise consumer signature methods: HMAC-SHA1, RSA-SHA1, plaintext over a secure channel (SSL)
  • 71. current status of OAuth oauth.net
  • 72. current status of OAuth oauth.net Auth 1.0 protocol (RFC 5849)
  • 73. current status of OAuth oauth.net Auth 1.0 protocol (RFC 5849) OAuth 2.0 working draft
  • 74. current status of OAuth oauth.net Auth 1.0 protocol (RFC 5849) OAuth 2.0 working draft several libraries for consumers and service providers
  • 75. links OAuth spec http://oauth.net PECL Extension http://pecl.php.net/oauth Fireeagle http://fireeagle.yahoo.net FE library (PHP) https://github.com/myelin/fireeagle-php-lib
  • 77. credit OAuth - Open API Authentication by leahculver on Dec 01, 2007 Implementing OAuth with PHP by Lorna Mitchell on May 17, 2011 Using OAuth with PHP by David Ingram on Nov 04, 2010

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n