11<?php namespace Dingo \Api \Auth ;
22
33use Exception ;
4+ use BadMethodCallException ;
45use Illuminate \Http \Request ;
56use Dingo \Api \Http \Response ;
67use Dingo \Api \Routing \Router ;
@@ -25,6 +26,13 @@ class Shield {
2526 */
2627 protected $ providers ;
2728
29+ /**
30+ * The provider used for authentication.
31+ *
32+ * @var \Dingo\Api\Auth\Provider
33+ */
34+ protected $ provider ;
35+
2836 /**
2937 * Authenticated user ID.
3038 *
@@ -68,7 +76,11 @@ public function authenticate(Request $request, Route $route)
6876 {
6977 try
7078 {
71- return $ this ->userId = $ provider ->authenticate ($ request , $ route );
79+ $ id = $ provider ->authenticate ($ request , $ route );
80+
81+ $ this ->provider = $ provider ;
82+
83+ return $ this ->userId = $ id ;
7284 }
7385 catch (UnauthorizedHttpException $ exception )
7486 {
@@ -144,4 +156,44 @@ public function check()
144156 return ! is_null ($ this ->user ());
145157 }
146158
159+ /**
160+ * Get the provider used for authentication.
161+ *
162+ * @return \Dingo\Api\Auth\Provider
163+ */
164+ public function getProvider ()
165+ {
166+ return $ this ->provider ;
167+ }
168+
169+ /**
170+ * Determine if the provider used was an OAuth 2.0 provider.
171+ *
172+ * @return bool
173+ */
174+ public function usedOAuth ()
175+ {
176+ return $ this ->getProvider () instanceof OAuth2ProviderInterface;
177+ }
178+
179+ /**
180+ * Magically call methods on the authenticated provider used.
181+ *
182+ * @param string $method
183+ * @param array $parameters
184+ * @return mixed
185+ * @throws \BadMethodCallException
186+ */
187+ public function __call ($ method , $ parameters )
188+ {
189+ $ provider = $ this ->getProvider ();
190+
191+ if (method_exists ($ provider , $ method ))
192+ {
193+ return call_user_func_array ([$ provider , $ method ], $ parameters );
194+ }
195+
196+ throw new BadMethodCallException ('Method " ' .$ method .'" not found. ' );
197+ }
198+
147199}
0 commit comments