@@ -90,58 +90,28 @@ protected function _getUserInfo($code)
9090 )
9191 );
9292
93- // Make the request for the access token
94- if (extension_loaded ('curl ' )) {
95- $ curl = curl_init ();
96- curl_setopt ($ curl , CURLOPT_URL , GOOGLE_AUTH_OAUTH2_URL );
97- curl_setopt ($ curl , CURLOPT_POST , 1 );
98- curl_setopt ($ curl , CURLOPT_POSTFIELDS , $ content );
99- curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
100- curl_setopt ($ curl , CURLOPT_PORT , 443 );
101- curl_setopt ($ curl , CURLOPT_HTTPHEADER , $ headers );
102- $ response = curl_exec ($ curl );
103- $ status = curl_getinfo ($ curl , CURLINFO_HTTP_CODE );
104-
105- if ($ status != 200 ) {
106- throw new Zend_Exception ('Access token request failed: ' .$ response );
107- }
108- } else {
109- $ context = array ('http ' => array ('method ' => 'POST ' , 'header ' => $ headers , 'content ' => $ content ));
110- $ context = stream_context_create ($ context );
111- $ response = file_get_contents (GOOGLE_AUTH_OAUTH2_URL , false , $ context );
93+ // Make the request for the access token.
94+ $ context = array ('http ' => array ('method ' => 'POST ' , 'header ' => $ headers , 'content ' => $ content ));
95+ $ context = stream_context_create ($ context );
96+ $ response = file_get_contents (GOOGLE_AUTH_OAUTH2_URL , false , $ context );
11297
113- if ($ response === false ) {
114- throw new Zend_Exception ('Access token request failed. ' );
115- }
98+ if ($ response === false ) {
99+ throw new Zend_Exception ('Access token request failed. ' );
116100 }
117101
118102 $ response = json_decode ($ response );
119103 $ accessToken = $ response ->access_token ;
120104 $ tokenType = $ response ->token_type ;
121105
122- // Use the access token to request info about the user
106+ // Use the access token to request info about the user.
123107 $ headers = 'Authorization: ' .$ tokenType .' ' .$ accessToken ;
108+ $ context = array ('http ' => array ('header ' => $ headers ));
109+ $ context = stream_context_create ($ context );
110+ $ params = 'fields=emails/value,id,name(familyName,givenName) ' ;
111+ $ response = file_get_contents (GOOGLE_AUTH_PLUS_URL .'? ' .urlencode ($ params ), false , $ context );
124112
125- if (extension_loaded ('curl ' )) {
126- $ curl = curl_init ();
127- curl_setopt ($ curl , CURLOPT_URL , GOOGLE_AUTH_PLUS_URL );
128- curl_setopt ($ curl , CURLOPT_RETURNTRANSFER , true );
129- curl_setopt ($ curl , CURLOPT_PORT , 443 );
130- curl_setopt ($ curl , CURLOPT_HTTPHEADER , $ headers );
131- $ response = curl_exec ($ curl );
132- $ status = curl_getinfo ($ curl , CURLINFO_HTTP_CODE );
133-
134- if ($ status != 200 ) {
135- throw new Zend_Exception ('Get Google user info request failed: ' .$ response );
136- }
137- } else {
138- $ context = array ('http ' => array ('header ' => $ headers ));
139- $ context = stream_context_create ($ context );
140- $ response = file_get_contents (GOOGLE_AUTH_PLUS_URL , false , $ context );
141-
142- if ($ response === false ) {
143- throw new Zend_Exception ('Get Google user info request failed. ' );
144- }
113+ if ($ response === false ) {
114+ throw new Zend_Exception ('Get Google user info request failed. ' );
145115 }
146116
147117 $ response = json_decode ($ response );
@@ -172,7 +142,7 @@ protected function _createOrGetUser($info)
172142 $ closeRegistration = (int ) $ this ->Setting ->getValueByNameWithDefault ('close_registration ' , 1 );
173143 if ($ closeRegistration === 1 ) {
174144 throw new Zend_Exception (
175- 'Access to this instance is by invitation ' . ' only, please contact an administrator. '
145+ 'Access to this instance is by invitation only, please contact an administrator. '
176146 );
177147 }
178148 $ user = $ this ->User ->createUser ($ info ['email ' ], null , $ info ['firstName ' ], $ info ['lastName ' ], 0 , '' );
0 commit comments