liyu001989 / lumen-api-demo Goto Github PK
View Code? Open in Web Editor NEWLumen rest api demo with Dingo/Api, JWT, CORS, PHPUNIT
Home Page: http://lumen.lyyw.info/apidoc/
License: MIT License
Lumen rest api demo with Dingo/Api, JWT, CORS, PHPUNIT
Home Page: http://lumen.lyyw.info/apidoc/
License: MIT License
➜ lumen-api-demo git:(master) ✗ php artisan key:generate
Application key [eFoEZeANciqkaM8YdoTeKXN9dKRUoXsN] set successfully.
➜ lumen-api-demo git:(master) ✗ php artisan jwt:generate
[Symfony\Component\Console\Exception\CommandNotFoundException]
Command "jwt:generate" is not defined.
Did you mean one of these?
key:generate
jwt:secret
➜ lumen-api-demo git:(master) ✗ php artisan key:generate
Application key [olwMeLDwDuQ9eKKoIZ7RWZmXm2WMDPuo] set successfully.
以上生成的key需要手动拷贝到 .env里面,好像laravel5.1是自动跟新该文件的。另外要使以上命令能运行需要按照以下的步骤设置一下。
Lumen Micro Framework => php artisan key:generate
jwt身份验证,框架是否还要加一些别的加密方式,如果私有key之类的。不知这个框架是否支持ssl.每次都在这边打扰你,怪不好意思的。是否可加我qq:121419067
file: app/Repositories/Eloquent/BaseRepository.php
public function where(array $data)
{
$this->model = $this->model->where($data);
return $this;
}
$model->where() will call the magic method __call, and get the new instance of '\Illuminate\Database\Eloquent\Builder' rather than the '\Illuminate\Database\Eloquent\Model'
app/Http/Controllers/Api/V1/UserController.php:6
更改为
use ApiDemo\Repositories\Contracts\UserRepositoryInterface;
//policy中修改资源的权限 UserOriResPolicy
public function update(User $user,UserOriFiles $userOriFiles){
return $user->uid === $userOriFiles->author_id;
}
// controller中的方法
public function update($id){
//侧路模式的权限判断
$userOriFile = UserOriFiles::find($id);
$isok = $this->authorize('update',$userOriFile);
最后接口一直报错
“This action is unauthorized”,
google 上有这个问题,但没有回答,你有在项目中用到Policy 吗?
https://www.laracasts.com/discuss/channels/laravel/laravel-54-policies-not-working-with-jwt
有个问题想请教下,关于 Token 的刷新机制的。
通过什么方式来刷新 Token 呢?是在请求返回 Token 失效之后去请求刷新一下 Token?然后再请求上次的数据吗?还是过期之前就去刷新?
// jwt 需要实现的方法
public function getJWTIdentifier()
{
return $this->getKey();
}
// jwt 需要实现的方法
public function getJWTCustomClaims()
{
return [];
}
想问下这两个函数主要要实现什么?是否能具体说明?非常感谢。
No input file specified.
http://lumen.com这个是本地nginx重定向与app,public等同级目录
还有就是apidoc文件无法打开
我现在是这样子手动加载使用。我看见你的demo里面没有其他关于includeUser调用的代码。自己尝试了很久也没发现可以自动加载的。
return $this->response()
->paginator($articles, (new ArticleTransformer)->setDefaultIncludes(['user']));
或者其他项目能兼容一起运行方便整合的也可以
lumen.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Symfony\Component\HttpFoundation\Response::header()' in /data/wwwroot/yi.dizeng.net/app/Http/Middleware/Cors.php:43
不知道哪的问题,有空了研究
In Connection.php line 664:
could not find driver (SQL: select * from information_schema.tables where table_schema = chat and table
_name = migrations)
In Connector.php line 67:
could not find driver
First thing, thank you to create this very useful demo API in Lumen.
I have a question related to work around using PHP session in Lumen 5.2 and 5.3. I know it's removed in these version. Just wonder if you have any advice if I want to use Session.
Again thank you very much
今天碰到一个问题,java开发的安卓,只能访问http status200的状态,其他400,500都不解析。晕死。这框架本身很多就是抛出异常,都是400,500的。不知如何解决这种问题。研究了一天,没有头绪。不知能否给出一个解决方案,千分感谢
meta中的links格式问题,如果links为空,返回一个空数组,反之返回一个对象,这种数据不一致的情况算bug吗?具体源码出在这里\vendor\league\fractal\src\Serializer\ArraySerializer.php, $pagination['links'] = [];
if ($currentPage > 1) {
$pagination['links']['previous'] = $paginator->getUrl($currentPage - 1);
}
if ($currentPage < $lastPage) {
$pagination['links']['next'] = $paginator->getUrl($currentPage + 1);
}
这里如果 $pagination['links'] 没有值的情况下,直接就输入出了初始化的这个[]
在验证微信服务器的时候,提示:
ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined method Symfony\Component\HttpFoundation\Response::header()
我知道可能是dingo response的问题,我想自定义一个controller不使用dingo的response或者是不使用dingo的middleware,但是我是菜鸟,花了很长时间还是没有弄好,
请您看下是怎么回事
我在做update操作的时候接受不都put/patch过来的数据,get,post,delete都行。不知道是不是dingo哪里没有配置好。lumen 5.3
app.php中把这个注释打开后报错,不太清楚这个逻辑,请问能讲下吗。
app('Dingo\Api\Auth\Auth')->extend('jwt', function ($app) {
return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
});
您好,请问如何能统一dingo api返回的异常处理结构,现在一旦报异常,就只有messaage和status_code2个字段;比如我用laravel5.4的用户授权中,采用Policy方式,在路由中加can:update,**,来验证授权,一旦授权不允许,会返回
{ "message": "This action is unauthorized.", "status_code": 500 }
我想自定义这个结构。
在本地调试的,不知道怎么回事,重新下载最新版,全新安装的也是这种情况 php version 5.6.27 + apache 我测试了https://lumen.lyyw.info/api/user 没有返回这个错误,请帮助看下,多谢
流程:
1.通过https://lumen.lyyw.info/api/users,post用户,得到token
2.通过https://lumen.lyyw.info/api/user header里面Authorization为:Bearer {token}
流程应该是没有问题的,用的postman调试的
Hi Yu Li, I don't know the best way to contact you. Do you consider writing this in English? Also do you have an English version of this -> http://oomusou.io/laravel/laravel-architecture/
$app->middleware
后生效。$app->middleware([
// 根据 accept-language 设置语言
'locale' => App\Http\Middleware\ChangeLocale::class,
'cors' => palanik\lumen\Middleware\LumenCors::class,
]);
$app->routeMiddleware([
//'cors' => palanik\lumen\Middleware\LumenCors::class,
'auth' => App\Http\Middleware\Authenticate::class,
'serializer' => \Liyu\Dingo\SerializerSwitch::class,
]);
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next) {
if ($request->isMethod('OPTIONS')) {
$response = new Response("", 200);
}
else {
$response = $next($request);
}
http://lumen.jmqu.cn/auth/register
post
email:[email protected]
password:xxxx
{
"message": "Declaration of ApiDemo\Repositories\Eloquent\BaseRepository::update() must be compatible with ApiDemo\Repositories\Contracts\RepositoryInterface::update(ApiDemo\Repositories\Contracts\int $id, array $attributes)",
"code": 64,
"status_code": 500
}
报这个错是什么原因?
PostController中的
public function show($id)
{
// $post = $this->post->findOrFail($id); <-写错了
$post = Post::findOrFail($id);
return $this->response->item($post, new PostTransformer());
}
我看了最近的升级,会不会和之前的版会冲突?更新的东西挺多的。
请问能使用模糊查询吗,where(array $data)->paginate(); 这样只能正确匹配,我想进行模糊匹配的,像like %abd%
➜ ~ homestead edit
- map: h.lumen-api-demo
to: /home/vagrant/Code/lumen-api-demo/public
/etc/hosts:
127.0.0.1 h.luemn-api-demo
vagrant halt
vagrant up -provision
➜ ~ curl http://h.lumen-api-demo:8000/api/auth/signin
curl: (6) Could not resolve host: h.lumen-api-demo
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.