我们有一个带有端点的API,用于我们想要限制访问的用户配置文件信息。
我们的应用程序后端是在Slim框架上用PHP构建的,所以我们在路由中间件时处理授权:
class Authorization {
public function authorizeAccess() {
... // check if oauth token corresponds to the correct id
}
}
$authorizer = new Authorization();
$app->get('/user/:id/profile', [$authorizer, 'authorizeAccess'], function() use ($app) {
...
};
这是一个很好的方法吗?