我已经为我的Web应用程序创建了一个API。现在,我想授予访问权限,但是在授予访问权限之前,我需要一种机制,例如提供客户端ID和密钥的Facebook API,Twitter API,Google API。当前,我正在使用JWT AuthController,使用他的凭据登录用户并返回令牌,我不希望用户登录。
我希望用户可以使用客户端ID和密钥访问我的API吗?另一件事是,我将如何为用户创建客户端ID和秘密密钥?
使用JWT Auth可以实现吗?
有什么帮助吗?
我已经阅读了这篇文章,并且非常有前途,但是在发布了几篇文章后,建议使用oauth2,在这里您可以:
https://laracasts.com/discuss/channels/lumen/api-authorization-via-public-and-secret-keys
引号:
只需将类添加到您的API配置中即可。
命名空间App \ Providers \ Guard;
使用Dingo \ Api \ Auth \ Provider \ Authorization; 使用Dingo \ Api \ Routing \ Route; 使用Illuminate \ Http \ Request; 使用Symfony \ Component \ HttpKernel \ Exception \ UnauthorizedHttpException;
GuardProvider扩展类Authorization {/ ** *获取提供者授权方法。* * @返回字符串* /公共函数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; } }
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句