Ram*_*aja 5 api web-services jwt laravel lumen
我为我的 Web 应用程序创建了一个 API。现在我想访问世界,但在授予访问权限之前,我想要像 Facebook API、Twitter API、提供客户端 ID 和密钥的 Google API 之类的机制。目前,我正在使用 JWT AuthController,用户使用他的凭据登录并返回一个令牌,我不希望用户登录。
我希望用户可以使用客户端 ID 和密钥访问我的 API?另一件事是,我将如何为用户创建客户端 ID 和密钥?
这可以使用 JWT 身份验证来实现吗?
有什么帮助吗?
我已经阅读了这篇文章,并且很有希望,但在几篇文章之后,它建议使用 oauth2,在这里:
https://laracasts.com/discuss/channels/lumen/api-authorization-via-public-and-secret-keys
引号:
只需将类添加到您的 API 配置中即可。
Run Code Online (Sandbox Code Playgroud)namespace App\Providers\Guard; use Dingo\Api\Auth\Provider\Authorization; use Dingo\Api\Routing\Route; use Illuminate\Http\Request; use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException; class GuardProvider extends Authorization { /** * Get the providers authorization method. * * @return string */ public function getAuthorizationMethod() { return 'X-Authorization'; } /** * Authenticate the request and return the authenticated user instance. * * @param \Illuminate\Http\Request $request * @param \Dingo\Api\Routing\Route $route * * @return mixed */ public function authenticate(Request $request, Route $route) { $key = $request->header(env('API_AUTH_HEADER', 'X-Authorization')); if (empty($key)) $key = $request->input(env('API_AUTH_HEADER', 'X-Authorization')); if (empty($key)) throw new UnauthorizedHttpException('Guard', 'The supplied API KEY is missing or an invalid authorization header was sent'); $user = app('db')->select("SELECT * FROM users WHERE users.key = ?", [$key]); if (!$user) throw new UnauthorizedHttpException('Guard', 'The supplied API KEY is not valid'); return $user; } }
归档时间: |
|
查看次数: |
4037 次 |
最近记录: |