1 | <?php |
||
16 | class TokenParser |
||
17 | { |
||
18 | /** |
||
19 | * @var \Illuminate\Http\Request |
||
20 | */ |
||
21 | protected $request; |
||
22 | |||
23 | /** |
||
24 | * The header name |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $header = 'authorization'; |
||
29 | |||
30 | /** |
||
31 | * The header prefix |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $prefix = 'bearer'; |
||
36 | |||
37 | /** |
||
38 | * The query string key |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $query = 'token'; |
||
43 | |||
44 | /** |
||
45 | * @param \Illuminate\Http\Request $request |
||
46 | */ |
||
47 | 10 | public function __construct(Request $request) |
|
51 | |||
52 | /** |
||
53 | * Attempt to parse the token from some other possible headers |
||
54 | * |
||
55 | * @return false|string |
||
56 | */ |
||
57 | 10 | protected function fromAltHeaders() |
|
63 | |||
64 | /** |
||
65 | * Try to parse the token from the request header |
||
66 | * |
||
67 | * @return false|string |
||
68 | */ |
||
69 | 10 | public function fromHeader() |
|
79 | |||
80 | /** |
||
81 | * Try to get the token from the route |
||
82 | * |
||
83 | * @return false|string |
||
84 | */ |
||
85 | 6 | public function fromRoute() |
|
89 | |||
90 | /** |
||
91 | * Try to parse the token from the request query string |
||
92 | * |
||
93 | * @return false|string |
||
94 | */ |
||
95 | 6 | public function fromQueryString() |
|
99 | |||
100 | /** |
||
101 | * Try to parse the token from either the header or query string |
||
102 | * |
||
103 | * @return false|string |
||
104 | */ |
||
105 | 10 | public function parseToken() |
|
109 | |||
110 | /** |
||
111 | * Check whether a token exists in the request |
||
112 | * |
||
113 | * @return boolean |
||
114 | */ |
||
115 | 10 | public function hasToken() |
|
119 | |||
120 | /** |
||
121 | * Set the request instance. |
||
122 | * |
||
123 | * @param \Illuminate\Http\Request $request |
||
124 | * |
||
125 | * @return TokenParser |
||
126 | */ |
||
127 | 2 | public function setRequest(Request $request) |
|
133 | |||
134 | /** |
||
135 | * Set the header name |
||
136 | * |
||
137 | * @param string $headerName |
||
138 | * |
||
139 | * @return TokenParser |
||
140 | */ |
||
141 | public function setHeaderName($headerName) |
||
147 | |||
148 | /** |
||
149 | * Set the header prefix |
||
150 | * |
||
151 | * @param string $headerPrefix |
||
152 | * |
||
153 | * @return TokenParser |
||
154 | */ |
||
155 | public function setHeaderPrefix($headerPrefix) |
||
161 | |||
162 | /** |
||
163 | * Set the query string |
||
164 | * |
||
165 | * @param string $queryString |
||
166 | * |
||
167 | * @return TokenParser |
||
168 | */ |
||
169 | public function setQueryString($queryString) |
||
175 | } |
||
176 |