php


Google oauth2 - automatic authentication?


Is it possible to make automatic Google authentication without going through the page 'choose account and enter password', instead passing those as PHP variables for example $email and $password or something like that.
Basicly I want to use some google API's without forcing users to login to google(if they don't have google account), just use them automatic with mine account.
Currently I use this code, but it forces me to the login page/choose account page the first time:
if (!$oauth_credentials = getOAuthCredentialsFile()) {
echo missingOAuth2CredentialsWarning();
return;
}
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
$client = new Google_Client();
$client->setAccessType("offline");
$client->setAuthConfig($oauth_credentials);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$service = new Google_Service_Drive($client);
// add "?logout" to the URL to remove a token from the session
if (isset($_REQUEST['logout'])) {
unset($_SESSION['upload_token']);
}
if (isset($_GET['code'])) {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
//print_r($token);die;
if (!empty($token['refresh_token'])) {
$_SESSION['refresh_token'] = $token['refresh_token'];
}
$client->setAccessToken($token);
// store in the session also
$_SESSION['upload_token'] = $token;
if (isset($_COOKIE['refresh_token22']) && empty($token['refresh_token'])) {
$_SESSION['upload_token']['refresh_token'] = $_COOKIE['refresh_token22'];
}
if (!empty($token['refresh_token'])) {
setcookie('refresh_token22', $token['refresh_token'], 2147000000);
}
// redirect back to the example
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
}
// set the access token as part of the client
if (!empty($_SESSION['upload_token'])) {
$client->setAccessToken($_SESSION['upload_token']);
if ($client->isAccessTokenExpired()) {
echo "<br>Access Token expired.<br>";
unset($_SESSION['upload_token']);
header('Location: http://nikolai.frontendfactory.com/google?expired=1');
}
} else {
//$client->setApprovalPrompt('force');
$authUrl = $client->createAuthUrl();
}

Related Links

Generate json to php find ID value through php [duplicate]
Android Database: How to display the Many-to-many Relationship in my PHP file
PHP ternary operators: if/else if/else with NULL, 0 and 1
AJAX Post 500 error
MySQL on delete cascade remove parent_id on pk_id remove
rename() not working in cron job
decryption data using php rijndael-128 decryption
PHP array iteration in loop and put fetched results in a table with MySQL
ErrorBag is always empty in Laravel 5.2
Looping through a DateTime object array
How to make Magento 'Show out of stock products' option different per website/store view?
mod rewrite for all requests after a directory
How to assign a table name a variable's string value when created?
extract title xpath if code xpath is present
How can i generate a nested array in php using data from mysql dynamically? [duplicate]
How can I get current page title in WordPress?

Categories

HOME
class
typelite
workflow
braintree
yql
mathematical-optimization
liferay-7
openfoam
fedora
position
telegraf
slide
nsstring
fbloginview
outlook-restapi
mahout-recommender
async-await
pinterest
rest-assured
l20n
gravity
gmp
cloudsim
nose
bazaar
jest
morris.js
echosign
tortoisehg
react-bootstrap-table
opnet
delayed-job
lxml
listjs
cloudera-manager
creation
textmate2
cargo
spring-restcontroller
newtons-method
robust
spooler
axis
adblock
rm
extjs4.1
.when
msxml
sidewaffle
perl-data-structures
gapi
qtextedit
mifos
libharu
gcloud-node
node-glob
processor
taco
chicagoboss
vdm-sl
darwin
abstract-factory
flow-js
sql-processor
google-hangouts
producer
berkeley-db-xml
object-code
coding-efficiency
windows-messages
wso2bam
san
sly-scroller
django-filebrowser
semantic-merge
viewpagerindicator
cakeyframeanimation
dropshadow
dynamic-c
nsrangeexception
kext
simile
explicit
sscli
j2mepolish
rawcontacts
database-cloning

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App