SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

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
Aaron Parecki
 
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
Antonio Sanso
 
OAuth 2 at Webvisions
OAuth 2 at WebvisionsOAuth 2 at Webvisions
OAuth 2 at Webvisions
Aaron Parecki
 

Was ist angesagt? (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
 

Ähnlich wie OAuth using PHP5

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
Bastian 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 oauth
Priyanka Aash
 
Learn with WSO2 - API Security
Learn with WSO2 - API Security Learn with WSO2 - API Security
Learn with WSO2 - API Security
WSO2
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

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

Hinweis der Redaktion

  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