Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- accessToken = GoogleAuthUtil.getToken(
- AuthenticatorActivity.this,
- Plus.AccountApi.getAccountName(Common.mGoogleApiClient),
- "oauth2:https://www.googleapis.com/auth/plus.me https://www.googleapis.com/auth/plus.login email"
- );
- https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.$_POST['google_access_token']
- if (!isset($_POST['google_access_token'])) {
- throw new Exception('missing google_access_token');
- }
- $client = new Google_Client();
- $client->setApplicationName("GiverHub");
- $client->setClientId($this->config->item('google_client_id'));
- $client->setClientSecret($this->config->item('google_client_secret'));
- $client->setDeveloperKey($this->config->item('google_developer_key'));
- $client->setRedirectUri($this->config->item('google_redirect_uri'));
- $client->setScopes([
- 'https://www.googleapis.com/auth/plus.login',
- 'https://www.googleapis.com/auth/plus.me',
- 'email',
- ]);
- try {
- $client->authenticate($_POST['google_access_token']); // if i remove this the rest of the code below works! ...
- $reqUrl = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token='.$_POST['google_access_token'];
- $req = new Google_Http_Request($reqUrl);
- $io = $client->getIo();
- $response = $io->executeRequest($req);
- $response = $response[0];
- $response = json_decode($response, true);
- if ($response === null) {
- throw new Exception('Failed to check token. response null');
- }
- if ($response['issued_to'] !== '466530377541-s7cfm34jpf818gbr0547pndpq9songkg.apps.googleusercontent.com') {
- throw new Exception('Invalid access token. issued to wrong client id: '. print_r($response, true));
- }
- if (!isset($response['user_id'])) {
- throw new Exception('Missing user_id');
- }
- if (!isset($response['email'])) {
- throw new Exception('Missing email');
- }
- /** @var EntityUser $user */
- $user = Common::create_member_google([
- 'id' => $response['user_id'],
- 'email' => $response['email'],
- 'given_name' => '',
- 'family_name' => '',
- ]);
- $user->login($this->session);
- if ($user instanceof EntityUser) {
- echo json_encode( [ 'success' => true, 'user' => $user ] );
- } else {
- echo json_encode( [ 'success' => false, 'msg' => $user ] );
- }
- } catch(Exception $e) {
- echo json_encode(['success' => false, 'msg' => $e->getMessage()]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement