-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGooglecloudauthController.php
46 lines (38 loc) · 1.28 KB
/
GooglecloudauthController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace inquid\googlecloudprint;
use Yii;
use yii\web\Controller;
/**
* Googlecloudauth controller for the `@inquid/googlecloudprint` components
*/
class GooglecloudauthController extends Controller
{
/**
* @return redirect Url
*/
public function actionIndex()
{
$request = Yii::$app->request;
if(count($request->get()) > 0 ){
$code = $request->get('code',null);
if($code != null){
$responseObj = Yii::$app->GoogleCloudPrint->getRefreshToken($code);
if(isset($responseObj->access_token)) Yii::$app->GoogleCloudPrint->setAuthTokenByResponce($responseObj->access_token);
if(isset($responseObj->refresh_token)){
Yii::$app->GoogleCloudPrint->setRefreshTokenSession($responseObj->refresh_token);
return $this->redirect(Yii::$app->GoogleCloudPrint->getRedirectUrl());
}
}
}
return $this->redirect(Yii::$app->GoogleCloudPrint->getAuthUrl());
}
/**
* Remove Refresh Token Session
* Remove Redirect Url Session
* @return redirect to Home page
*/
public function actionRemove(){
Yii::$app->GoogleCloudPrint->removeTokenSession();
return $this->goHome();
}
}