php - Integrating Google OAuth API with existing user system? -


i have simple user system basic information: email , password. instead of using google api "sign in" feature:

is there way can "link" user's youtube channel account?

is there way can link multiple channels user's account? if so, how keep track of user data from?

i have written few php classes take care of google's oauth flow, storing access token, expiration time, , refresh token in database (you may think "don't reinvent wheel", prefer learn writing these classes).

as kept going through logic , how lay out, did not understand how link user's account previous account. eg: when login, how user's linked channels?

here of code client.php

public function authinticate($authorizationcode) {     // need post request access token , refresh token     $post = array("grant_type" => "authorization_code", "code" => $authorizationcode, "client_id" => $this->clientid, "client_secret" => $this->clientsecret, "redirect_uri" => $this->redirecturi);     $posttext = http_build_query($post);     $ch = curl_init();     curl_setopt($ch, curlopt_url, self::google_oauth_token_url);     curl_setopt($ch, curlopt_returntransfer, true);     curl_setopt($ch, curlopt_post, true);     curl_setopt($ch, curlopt_postfields, $posttext);      curl_setopt($ch, curlopt_ssl_verifypeer, false);     curl_setopt($ch, curlopt_ssl_verifyhost, false);     $result = curl_exec($ch);      //decode returned values     $responsearray = json_decode($result, true);      // set out values     $this->accesstoken = $responsearray['access_token'];     $this->refreshtoken = $responsearray['refresh_token'];     $this->expiresin = $responsearray['expires_in']; } 

and tokenstorage class:

// store token data response google, (if reresh token passed value, means user authorized our application, need store value) public function storetokendata($channelid, $accesstoken, $refreshtoken, $expirationtime) {     $firstrequest = "insert tokens (channelid, accesstoken, refreshtoken, expirationtime) values (?, ?, ?, date_add(now(), interval $expirationtime second)";     $linkedrequest = "insert tokens (channelid, accesstoken, expirationtime) values (?, ?, date_add(now(), interval $expirationtime second)";      if($refreshtoken == null)     {         if ($storetokendata = global $mysqli->prepare($firstrequest))          {                 $storetokendata->bind_param('sss', $channelid, $accesstoken, $refreshtoken);              if($storetokendata->execute()) {                 // data stored success...                 return true;             } else {                 // happened...                 return false;             }         }     }     else     {         if ($storetokendata = global $mysqli->prepare($linkedrequest))          {                 $storetokendata->bind_param('ss', $channelid, $accesstoken);              if($storetokendata->execute()) {                 // data stored success...                 return true;             } else {                 // happened...                 return false;             }         }     } } 

problem

you want integrate existing login solution , link users youtube accounts.

recommendation

why not use php api on @ youtube? (api) collect login , youtube account links new table , ask user link accounts (when sign in using youtube account) logging both account , new login? after which, accounts can maintained in sync because extend login table new column of information or linked related table (of encrypted youtube links). @ least big idea. sure there several challenges make work have seen on other websites.

in essence build second login flow youtubers, connect via api. ask them login normal account , link logins using column in existing table or using new linked table foreign key allow multiple youtube pages/accounts. initial approach. link provided above connection youtube php api. haven't needed myself if need more precise please let me know.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -