1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OAuth\Helper; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\Finder\Finder; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Helper class to be used in sample code. |
9
|
|
|
*/ |
10
|
|
|
class Example |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var Finder |
14
|
|
|
*/ |
15
|
|
|
private $finder; |
16
|
|
|
|
17
|
|
|
public function __construct() |
18
|
|
|
{ |
19
|
|
|
$this->finder = new Finder(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function isCli(): bool |
23
|
|
|
{ |
24
|
|
|
return PHP_SAPI === 'cli'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
public function getFinder(): Finder |
29
|
|
|
{ |
30
|
|
|
$this->finder->in(__DIR__ . '/../../../examples/provider/'); |
31
|
|
|
return $this->finder; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getHeader(): string |
35
|
|
|
{ |
36
|
|
|
return <<<HTML |
37
|
|
|
<html> |
38
|
|
|
<head> |
39
|
|
|
<title></title> |
40
|
|
|
<meta charset="utf-8"> |
41
|
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/> |
42
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> |
43
|
|
|
<link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css"/> |
44
|
|
|
<link rel="stylesheet" href="/bootstrap/css/font-awesome.min.css"/> |
45
|
|
|
<link rel="stylesheet" href="/bootstrap/css/phpspreadsheet.css"/> |
46
|
|
|
<script src="/bootstrap/js/jquery.min.js"></script> |
47
|
|
|
<script src="/bootstrap/js/bootstrap.min.js"></script> |
48
|
|
|
</head> |
49
|
|
|
<body> |
50
|
|
|
<div class="container"> |
51
|
|
|
<div class="navbar navbar-default" role="navigation"> |
52
|
|
|
<div class="container-fluid"> |
53
|
|
|
<div class="navbar-header"> |
54
|
|
|
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse"> |
55
|
|
|
<span class="sr-only">Toggle navigation</span> |
56
|
|
|
<span class="icon-bar"></span> |
57
|
|
|
<span class="icon-bar"></span> |
58
|
|
|
<span class="icon-bar"></span> |
59
|
|
|
</button> |
60
|
|
|
<a class="navbar-brand" href="/">PHPoAuthLib</a> |
61
|
|
|
</div> |
62
|
|
|
<div class="navbar-collapse collapse"> |
63
|
|
|
</ul> |
64
|
|
|
<ul class="nav navbar-nav navbar-right"> |
65
|
|
|
<li><a href="https://github.com/Lusitanian/PHPoAuthLib"><i class="fa fa-github fa-lg" title="GitHub"></i> </a></li> |
66
|
|
|
</ul> |
67
|
|
|
</div> |
68
|
|
|
</div> |
69
|
|
|
</div> |
70
|
|
|
HTML; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function getFooter() |
74
|
|
|
{ |
75
|
|
|
return <<<HTML |
76
|
|
|
</body> |
77
|
|
|
</html> |
78
|
|
|
HTML; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getForm(): string |
82
|
|
|
{ |
83
|
|
|
return <<<HTML |
84
|
|
|
<form> |
85
|
|
|
<div class="form-group"> |
86
|
|
|
<label for="exampleInputEmail1">key</label> |
87
|
|
|
<input class="form-control" name="key" id="exampleInputEmail1" aria-describedby="emailHelp" placeholder="key"> |
88
|
|
|
</div> |
89
|
|
|
<div class="form-group"> |
90
|
|
|
<label for="exampleInputPassword1">secret</label> |
91
|
|
|
<input name="secret" class="form-control" id="exampleInputPassword1" placeholder="secret"> |
92
|
|
|
</div> |
93
|
|
|
<button type="submit" class="btn btn-primary">Submit</button> |
94
|
|
|
</form> |
95
|
|
|
HTML; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getContent(): string |
99
|
|
|
{ |
100
|
|
|
|
101
|
|
|
$response = $this->getHeader(); |
102
|
|
|
$response .= $this->getForm(); |
103
|
|
|
$response .= $this->getFooter(); |
104
|
|
|
|
105
|
|
|
return $response; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
public function isShowLink(): bool |
109
|
|
|
{ |
110
|
|
|
return true; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getCurrentUrl(): string |
114
|
|
|
{ |
115
|
|
|
return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?oauth=redirect&key='. urldecode($_GET['key']) . '&secret=' . urldecode($_GET['secret']); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function getErrorMessage($exception) |
119
|
|
|
{ |
120
|
|
|
echo '<div class="alert alert-danger">' . $exception->getMessage() . '</div>'; |
121
|
|
|
echo '<pre>'; |
122
|
|
|
print_r($exception) ; |
123
|
|
|
echo '</pre>'; |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|