Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Tenzing
/
pdf-customizer
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
f2a384d0
authored
2016-10-06 15:21:53 -0400
by
Jeff Balicki
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fixed google auth
1 parent
0fdce8be
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
154 deletions
app/Http/Controllers/ApiController.php
app/Http/Controllers/GoogledriveuploadpdfController.php
app/pdfModel.php
app/Http/Controllers/ApiController.php
View file @
f2a384d
...
...
@@ -154,8 +154,8 @@ class ApiController extends Controller
$pdf
=
$pdf
->
pdf
(
$pdfId
);
$response
=
$pdfId
;
$statusCode
=
200
;
//
$UploaqdPdf = new GoogledriveuploadpdfController();
//
$UploaqdPdf->google_drive_upload($folder, 'new_'.$pdfLocation,$pdfId,$cust_id);
$UploaqdPdf
=
new
GoogledriveuploadpdfController
();
$UploaqdPdf
->
google_drive_upload
(
$folder
,
'new_'
.
$pdfLocation
,
$pdfId
,
$cust_id
);
return
Response
::
json
(
$response
,
$statusCode
);
...
...
app/Http/Controllers/GoogledriveuploadpdfController.php
View file @
f2a384d
...
...
@@ -200,181 +200,125 @@ public function isGoogleFolderCreated($cust_id)
public
function
GoogleToken
()
{
session_start
();
require_once
realpath
(
dirname
(
__FILE__
)
.
'/../autoload.php'
);
session_start
();
$oath
=
new
pdfModel
();
$oath
=
$oath
->
getGoogleUserOath
(
2
)
->
get
();
//var_dump($oath);
$client
=
new
\Google_Client
();
$client
->
setScopes
(
array
(
'https://www.googleapis.com/auth/drive.file'
));
$client
->
setClientId
(
'206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
);
$client
->
setClientSecret
(
'ZzEE02Dqz7AKJLSklmL30LNd'
);
$client
->
setRedirectUri
(
'https://pdf-customizer.synapsus.co/auth/google/tokenCallback'
);
$client
->
setClientId
(
$oath
[
0
]
->
google_client_id
);
$client
->
setClientSecret
(
$oath
[
0
]
->
google_client_secret
);
$client
->
setRedirectUri
(
$oath
[
0
]
->
redirect_uri
);
$client
->
setAccessType
(
'offline'
);
$client
->
setApprovalPrompt
(
'force'
);
if
(
isset
(
$_GET
[
'code'
]))
{
$client
->
authenticate
(
$_GET
[
'code'
]);
$_SESSION
[
'token'
]
=
$client
->
getAccessToken
();
$redirect
=
'http://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$_SERVER
[
'PHP_SELF'
];
header
(
'Location: '
.
filter_var
(
$redirect
,
FILTER_SANITIZE_URL
));
return
;
}
if
(
isset
(
$_SESSION
[
'token'
]))
{
$client
->
setAccessToken
(
$_SESSION
[
'token'
]);
}
if
(
isset
(
$_REQUEST
[
'logout'
]))
{
unset
(
$_SESSION
[
'access_token'
]);
$client
->
revokeToken
();
}
/************************************************
If we have a code back from the OAuth 2.0 flow,
we need to exchange that with the authenticate()
function. We store the resultant access token
bundle in the session, and redirect to ourself.
************************************************/
if
(
isset
(
$_GET
[
'code'
]))
{
$client
->
authenticate
(
$_GET
[
'code'
]);
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$redirect
=
'http://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$_SERVER
[
'PHP_SELF'
];
header
(
'Location: '
.
filter_var
(
$redirect
,
FILTER_SANITIZE_URL
));
}
/************************************************
If we have an access token, we can make
requests, else we generate an authentication URL.
************************************************/
if
(
isset
(
$_SESSION
[
'access_token'
])
&&
$_SESSION
[
'access_token'
])
{
$client
->
setAccessToken
(
$_SESSION
[
'access_token'
]);
}
else
{
$authUrl
=
$client
->
createAuthUrl
();
}
/************************************************
If we're signed in we can go ahead and retrieve
the ID token, which is part of the bundle of
data that is exchange in the authenticate step
- we only need to do a network call if we have
to retrieve the Google certificate to verify it,
and that can be cached.
************************************************/
if
(
$client
->
getAccessToken
())
{
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$token_data
=
$client
->
verifyIdToken
()
->
getAttributes
();
}
echo
pageHeader
(
"User Query - Retrieving An Id Token"
);
if
(
$client_id
==
'206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
||
$client_secret
==
'ZzEE02Dqz7AKJLSklmL30LNd'
||
$redirect_uri
==
'http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback'
)
{
echo
missingClientSecretsWarning
();
}
?>
<div
class=
"box"
>
<div
class=
"request"
>
<?php
if
(
isset
(
$authUrl
))
{
echo
"<a class='login' href='"
.
$authUrl
.
"'>Connect Me!</a>"
;
}
else
{
echo
"<a class='logout' href='?logout'>Logout</a>"
;
}
?>
</div>
<div
class=
"data"
>
<?php
if
(
isset
(
$token_data
))
{
var_dump
(
$token_data
);
}
?>
</div>
</div>
<?php
echo
pageFooter
(
__FILE__
);
unset
(
$_SESSION
[
'token'
]);
$client
->
revokeToken
();
}
?>
<!doctype html>
<html>
<head>
<meta
charset=
"utf-8"
>
</head>
<body>
<header><h1>
Get Token
</h1></header>
<?php
if
(
$client
->
getAccessToken
())
{
$_SESSION
[
'token'
]
=
$client
->
getAccessToken
();
$token
=
json_decode
(
$_SESSION
[
'token'
]);
echo
"Access Token = "
.
$token
->
access_token
.
'<br/>'
;
echo
"Refresh Token = "
.
$token
->
refresh_token
.
'<br/>'
;
echo
"Token type = "
.
$token
->
token_type
.
'<br/>'
;
echo
"Expires in = "
.
$token
->
expires_in
.
'<br/>'
;
//echo "ID Token = " . $token->id_token . '<br/>';
echo
"Created = "
.
$token
->
created
.
'<br/>'
;
echo
"<a class='logout' href='?logout'>Logout</a>"
;
}
else
{
$authUrl
=
$client
->
createAuthUrl
();
print
"<a class='login' href='
$authUrl
'>Connect Me!</a><br/>"
;
echo
"<a class='logout' href='?logout'>Logout</a>"
;
}
}
public
function
GoogleTokenCode
()
{
session_start
();
require_once
realpath
(
dirname
(
__FILE__
)
.
'/../autoload.php'
);
$oath
=
new
pdfModel
();
$oath
=
$oath
->
getGoogleUserOath
(
2
)
->
get
();
$google_client_id
=
$oath
[
0
]
->
google_client_id
;
$client
=
new
\Google_Client
();
$client
->
setScopes
(
array
(
'https://www.googleapis.com/auth/drive.file'
));
$client
->
setClientId
(
'206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
);
$client
->
setClientSecret
(
'ZzEE02Dqz7AKJLSklmL30LNd'
);
$client
->
setRedirectUri
(
'https://pdf-customizer.synapsus.co/auth/google/tokenCallback'
);
$client
->
setClientId
(
$google_client_id
);
$client
->
setClientSecret
(
$oath
[
0
]
->
google_client_secret
);
$client
->
setRedirectUri
(
$oath
[
0
]
->
redirect_uri
);
$client
->
setAccessType
(
'offline'
);
$client
->
setApprovalPrompt
(
'force'
);
$client
->
authenticate
(
$_GET
[
'code'
]);
$_SESSION
[
'token'
]
=
$client
->
getAccessToken
();
if
(
isset
(
$_SESSION
[
'token'
]))
{
$client
->
setAccessToken
(
$_SESSION
[
'token'
]);
}
if
(
isset
(
$_REQUEST
[
'logout'
]))
{
unset
(
$_SESSION
[
'access_token'
]);
$client
->
revokeToken
();
}
/************************************************
If we have a code back from the OAuth 2.0 flow,
we need to exchange that with the authenticate()
function. We store the resultant access token
bundle in the session, and redirect to ourself.
************************************************/
if
(
isset
(
$_GET
[
'code'
]))
{
$client
->
authenticate
(
$_GET
[
'code'
]);
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$redirect
=
'http://'
.
$_SERVER
[
'HTTP_HOST'
]
.
$_SERVER
[
'PHP_SELF'
];
header
(
'Location: '
.
filter_var
(
$redirect
,
FILTER_SANITIZE_URL
));
}
/************************************************
If we have an access token, we can make
requests, else we generate an authentication URL.
************************************************/
if
(
isset
(
$_SESSION
[
'access_token'
])
&&
$_SESSION
[
'access_token'
])
{
$client
->
setAccessToken
(
$_SESSION
[
'access_token'
]);
}
else
{
$authUrl
=
$client
->
createAuthUrl
();
}
/************************************************
If we're signed in we can go ahead and retrieve
the ID token, which is part of the bundle of
data that is exchange in the authenticate step
- we only need to do a network call if we have
to retrieve the Google certificate to verify it,
and that can be cached.
************************************************/
if
(
$client
->
getAccessToken
())
{
$_SESSION
[
'access_token'
]
=
$client
->
getAccessToken
();
$token_data
=
$client
->
verifyIdToken
()
->
getAttributes
();
}
echo
pageHeader
(
"User Query - Retrieving An Id Token"
);
if
(
$client_id
==
'206523860143-kgs80emhfm1sof79nggd48gnhbl1j6ei.apps.googleusercontent.com'
||
$client_secret
==
'ZzEE02Dqz7AKJLSklmL30LNd'
||
$redirect_uri
==
'http://localhost:8888/pdf-customizer/public/auth/google/tokenCallback'
)
{
echo
missingClientSecretsWarning
();
}
?>
<div
class=
"box"
>
<div
class=
"request"
>
<?php
if
(
isset
(
$authUrl
))
{
echo
"<a class='login' href='"
.
$authUrl
.
"'>Connect Me!</a>"
;
}
else
{
echo
"<a class='logout' href='?logout'>Logout</a>"
;
}
?>
</div>
<div
class=
"data"
>
<?php
if
(
isset
(
$token_data
))
{
var_dump
(
$token_data
);
}
?>
</div>
</div>
<?php
echo
pageFooter
(
__FILE__
);
unset
(
$_SESSION
[
'token'
]);
$client
->
revokeToken
();
}
?>
<!doctype html>
<html>
<head>
<meta
charset=
"utf-8"
>
</head>
<body>
<header><h1>
Get Token
</h1></header>
<?php
$_SESSION
[
'token'
]
=
$client
->
getAccessToken
();
$token
=
json_decode
(
$_SESSION
[
'token'
]);
echo
"Access Token = "
.
$token
->
access_token
.
'<br/>'
;
echo
"Refresh Token = "
.
$token
->
refresh_token
.
'<br/>'
;
echo
"Token type = "
.
$token
->
token_type
.
'<br/>'
;
echo
"Expires in = "
.
$token
->
expires_in
.
'<br/>'
;
//echo "ID Token = " . $token->id_token . '<br/>';
echo
"Created = "
.
$token
->
created
.
'<br/>'
;
echo
"<a class='logout' href='?logout'>Logout</a>"
;
$oath
=
new
pdfModel
();
$oath
=
$oath
->
updateGoogleOath
(
$token
,
$google_client_id
);
}
...
...
app/pdfModel.php
View file @
f2a384d
...
...
@@ -46,6 +46,13 @@ class pdfModel extends Model
return
$folderId
;
}
public
function
updateGoogleOath
(
$token
,
$google_client_id
){
$folderId
=
DB
::
table
(
'googleOuth'
)
->
where
(
'google_client_id'
,
$google_client_id
)
->
insertGetId
(
array
(
'access_token'
=>
$token
->
access_token
,
'refresh_token'
=>
$token
->
refresh_token
)
);
return
'Saved'
;
}
public
function
getPdf
(
$id
){
...
...
@@ -181,17 +188,18 @@ class pdfModel extends Model
public
function
getGoogleUserOath
(
$id
){
$rows
=
DB
::
table
(
'googleOuth'
)
->
select
(
'*'
)
->
where
(
'googleOuth.user_id'
,
'='
,
$id
);
$rows
=
DB
::
table
(
'googleOuth'
)
->
where
(
'googleOuth.user_id'
,
'='
,
$id
);
return
$rows
;
}
public
function
getUserId
(
$id
){
$rows
=
DB
::
table
(
'users'
)
->
select
(
'id'
)
->
where
(
'email'
,
'='
,
$id
);
$rows
=
DB
::
table
(
'users'
)
->
where
(
'email'
,
'='
,
$id
);
return
$rows
;
...
...
Please
register
or
sign in
to post a comment