@@ -90,58 +90,28 @@ protected function _getUserInfo($code)
90
90
)
91
91
);
92
92
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 );
112
97
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. ' );
116
100
}
117
101
118
102
$ response = json_decode ($ response );
119
103
$ accessToken = $ response ->access_token ;
120
104
$ tokenType = $ response ->token_type ;
121
105
122
- // Use the access token to request info about the user
106
+ // Use the access token to request info about the user.
123
107
$ 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 );
124
112
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. ' );
145
115
}
146
116
147
117
$ response = json_decode ($ response );
@@ -172,7 +142,7 @@ protected function _createOrGetUser($info)
172
142
$ closeRegistration = (int ) $ this ->Setting ->getValueByNameWithDefault ('close_registration ' , 1 );
173
143
if ($ closeRegistration === 1 ) {
174
144
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. '
176
146
);
177
147
}
178
148
$ user = $ this ->User ->createUser ($ info ['email ' ], null , $ info ['firstName ' ], $ info ['lastName ' ], 0 , '' );
0 commit comments