[php/ZF] Google Apps account inloggen met AuthSub

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • Hipska
  • Registratie: Mei 2008
  • Laatst online: 15-09 21:08
Ik heb een domein met google apps.

Nu wou ik op de site ervan gebruikers laten inloggen met hun google apps account voor dit domein, zodat ze niet 2 maal een gebruikersnaam/wachtwoord hoeven aan te maken. Dit inloggen werkt perfect (stuurt de gebruiker door naar de speciale loginpagina voor domeinen) als ik het door RPX laat afhandelen.

Deze manier vind ik niet echt gebruiksvriendelijk omdat men dan telkens eerst de domeinnaam moet invullen vooraleer er naar de google inlogpagina geredirect word. Ook is het systeem dan rechtstreeks afhankelijk van de service van RPX. Ja zonder google gaat het inloggen ook niet, maar als google uitvalt is er al iets deftigs mis, terwijl RPX zorgt voor nog een extra afhankelijkheid en dus extra kans op falen bij inloggen.

Mijn oog was gevallen op een inlogclasse (Zend_Gdata_AuthSub) in het Zend Framework, waar je gebruikers op hun google account kan laten inloggen dmv een webinterface. Blijkbaar krijg ik het niet voor elkaar om deze in te zetten als login voor google apps for domain gebruikers.

Andere mogelijkheid was de openid implementatie gebruiken, maar daar krag ik telkens een discovery failed melding te zien (logisch, maar bij RPX lukt het wel).

Kan iemand mij een eindje in de goede richting helpen, hoe ik het wel zou kunnen doen?
Ik heb de Zend Framework, google Apps account en google Oauth documentaties meerdere malen overlopen en ben er niet erg veel wijzer uit gekomen.

Acties:
  • 0 Henk 'm!

  • mithras
  • Registratie: Maart 2003
  • Niet online
Als je AuthSub wil gebruiken zit je toch altijd met het redirecten? Dat is afaik een onderdeel van het mechanisme. Hetzelfde als je een non-Twitter website hebt die gebruik maakt van je account. Je wordt even gestuurd naar Twitter en dan weer terug. Hetzelfde voor Flickr, en nog veel meer online services.

Zover ik kan zien heb je een link met "klik hier om in te loggen" -> redirect naar Google -> inlog ok? -> redirect terug naar $website -> vang token op en sla op in sessie.
De snippet op de website lijkt me precies die eerste en laatste stap die je moet doen.

Tot slot: Google heeft zelf een uitleg over de OpenID implementatie. Ook ondersteunen ze OAuth wat waarschijnlijker nog makkelijker is om te implementeren. En van OAuth is een ZF Proposal welke tegenwoordig al in de incubator zit. Misschien wel de meest eenvoudige manier om authenticatie uit te voeren :)

Acties:
  • 0 Henk 'm!

  • Hipska
  • Registratie: Mei 2008
  • Laatst online: 15-09 21:08
Inderdaad, redirecten zal het altijd moeten zijn, daar ben ik me volledig bewust van. Maar ivm RPX bedoelde ik dat je op hun widget eerst moest kiezen voor OpenID, daarna example.com intypen en dan komt de redirect naar google apps inlogpagina waar je gebruikersnaam en ww moet intypen.

Aangezien die eerste stappen keuze welke google apps domein je gebruikt altijd gelijk zullen zijn lijkt het mij onhandig om nog te vragen naar het domein.

Over dat snippet op de site: Deze heb ik al geprobeerd, maar moet $my_calendar dan anders zijn? Ik vermoed haast van wel, want nu krijg ik telkens een gewoon google account inlogscherm. Deze code heb ik:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?php

/**
 * @see Zend_Loader
 */
require_once 'Zend/Loader.php';

/**
 * @see Zend_Gdata
 */
Zend_Loader::loadClass('Zend_Gdata');

/**
 * @see Zend_Gdata_AuthSub
 */
Zend_Loader::loadClass('Zend_Gdata_AuthSub');

/**
 * @see Zend_Gdata_ClientLogin
 */
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');

/**
 * @see Zend_Gdata_HttpClient
 */
Zend_Loader::loadClass('Zend_Gdata_HttpClient');

/**
 * @var string Location of AuthSub key file.  include_path is used to find this
 */
$_authSubKeyFile = null; // Example value for secure use: 'mykey.pem'

/**
 * @var string Passphrase for AuthSub key file.
 */
$_authSubKeyFilePassphrase = null;

/**
 * Returns the full URL of the current page, based upon env variables
 * 
 * Env variables used:
 * $_SERVER['HTTPS'] = (on|off|)
 * $_SERVER['HTTP_HOST'] = value of the Host: header
 * $_SERVER['SERVER_PORT'] = port number (only used if not http/80,https/443)
 * $_SERVER['REQUEST_URI'] = the URI after the method of the HTTP request
 *
 * @return string Current URL
 */
function getCurrentUrl() 
{
  global $_SERVER;

  /**
   * Filter php_self to avoid a security vulnerability.
   */
  $php_request_uri = htmlentities(substr($_SERVER['REQUEST_URI'], 0, strcspn($_SERVER['REQUEST_URI'], "\n\r")), ENT_QUOTES);

  if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') {
    $protocol = 'https://';
  } else {
    $protocol = 'http://';
  }
  $host = $_SERVER['HTTP_HOST'];
  if ($_SERVER['SERVER_PORT'] != '' &&
     (($protocol == 'http://' && $_SERVER['SERVER_PORT'] != '80') ||
     ($protocol == 'https://' && $_SERVER['SERVER_PORT'] != '443'))) {
    $port = ':' . $_SERVER['SERVER_PORT'];
  } else {
    $port = '';
  }
  return $protocol . $host . $port . $php_request_uri;
}

/**
 * Returns the AuthSub URL which the user must visit to authenticate requests 
 * from this application.
 *
 * Uses getCurrentUrl() to get the next URL which the user will be redirected
 * to after successfully authenticating with the Google service.
 *
 * @return string AuthSub URL
 */
function getAuthSubUrl() 
{
  global $_authSubKeyFile;
  $next = getCurrentUrl();
  $scope = '...'; // wat moet hier bij enkel inloggen?
  $session = true;
  if ($_authSubKeyFile != null) {
    $secure = true;
  } else {
    $secure = false;
  }
  return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, 
      $session);
}

/**
 * Outputs a request to the user to login to their Google account, including
 * a link to the AuthSub URL.
 * 
 * Uses getAuthSubUrl() to get the URL which the user must visit to authenticate
 *
 * @return void
 */
function requestUserLogin($linkText) 
{
  $authSubUrl = getAuthSubUrl();
  echo "<a href=\"{$authSubUrl}\">{$linkText}</a>"; 
}

/**
 * Returns a HTTP client object with the appropriate headers for communicating
 * with Google using AuthSub authentication.
 *
 * Uses the $_SESSION['sessionToken'] to store the AuthSub session token after
 * it is obtained.  The single use token supplied in the URL when redirected 
 * after the user succesfully authenticated to Google is retrieved from the 
 * $_GET['token'] variable.
 *
 * @return Zend_Http_Client
 */
function getAuthSubHttpClient() 
{
  global $_SESSION, $_GET, $_authSubKeyFile, $_authSubKeyFilePassphrase;
  $client = new Zend_Gdata_HttpClient();
  if ($_authSubKeyFile != null) {
    // set the AuthSub key
    $client->setAuthSubPrivateKeyFile($_authSubKeyFile, $_authSubKeyFilePassphrase, true);
  }
  if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
    $_SESSION['sessionToken'] = 
        Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token'], $client);
  } 
  $client->setAuthSubToken($_SESSION['sessionToken']);
  return $client;
}

/**
 * Processes loading of this sample code through a web browser.  Uses AuthSub
 * authentication and outputs a list of a user's calendars if succesfully 
 * authenticated.
 *
 * @return void
 */
function processPageLoad() 
{
  global $_SESSION, $_GET;
  if (!isset($_SESSION['sessionToken']) && !isset($_GET['token'])) {
    requestUserLogin('Please login to your Google Apps Account.');
  } else {
    $client = getAuthSubHttpClient();
    var_dump($client);
  }
}

/**
 * Main logic for running this sample code via the command line or,
 * for AuthSub functionality only, via a web browser.  The output of
 * many of the functions is in HTML format for demonstration purposes,
 * so you may wish to pipe the output to Tidy when running from the 
 * command-line for clearer results.
 *
 * Run without any arguments to get usage information
 */ 
 
  // running through web server - demonstrate AuthSub
  processPageLoad();
?>

[ Voor 79% gewijzigd door Hipska op 01-09-2009 16:53 ]


Acties:
  • 0 Henk 'm!

  • mithras
  • Registratie: Maart 2003
  • Niet online
Die url is de Zend_GData_Calendar::CALENDAR_EVENT_FEED_URI. Maar het ligt er een beetje aan wat je wil. Met AuthSub kan je afaik je authenticeren adhv je Google Apps account:
The AuthSub mechanism enables you to write web applications that acquire authenticated access Google Data services, without having to write code that handles user credentials.
Als je dat niet nodig hebt, maar slechts het uitlezen van een Google Calendar die onder Apps zit, volsta je volgens de documentation met dit:
PHP:
1
2
3
4
5
6
7
8
9
10
// Parameters for ClientAuth authentication
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "sample.user@gmail.com";
$pass = "pa$$w0rd";

// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);

// Create an instance of the Calendar service
$service = new Zend_Gdata_Calendar($client);
Direct onder dat voorbeeld staat een langer voorbeeld wat ook gebruikt maakt van AuthSub ("A Calendar service using AuthSub can be created in a similar, though slightly more lengthy fashion:"). Die is te lang om hier te posten, maar dat komt eigenlijk neer op het verhaal van mijn vorige post :)

Acties:
  • 0 Henk 'm!

  • Hipska
  • Registratie: Mei 2008
  • Laatst online: 15-09 21:08
Maar ik hoef helemaal niet een calendar API aan te spreken.

Ik wil enkel gebruikers laten inloggen dmv hun google apps for domains account.

En dat lijkt mij ook het probleem: ClientLogin classe ondersteund wel gemakkelijk Google Apps, maar bij AuthSub krijg ik het niet voor elkaar..

[ Voor 34% gewijzigd door Hipska op 01-09-2009 17:27 . Reden: aanvulling ]


  • Hipska
  • Registratie: Mei 2008
  • Laatst online: 15-09 21:08
Is bumpen toegestaan?

Volgens mij ziet het er naar uit dat inloggen met een google Apps account via AuthSub in zf niet mogelijk is.
Ook andere php oplossingen heb ik niet gevonden.

Voorlopig doe ik het nu door een aangepaste versie van de RPX widget te gebruiken, maar zoals eerder aangegeven zou ik dit liever niet doen op deze manier..

Acties:
  • 0 Henk 'm!

  • Hipska
  • Registratie: Mei 2008
  • Laatst online: 15-09 21:08
Niemand die verder nog een oplossing weet?
Pagina: 1