methods: {
login: function (e){
e.preventDefault();
this.standing = true; // Disables Login Button
axios.post('/oauth/token', {
email: this.email, // I verify with email
password: this.password,
username: this.username,
grant_type: 'password',
client_id: integer_of_client_id,
client_secret: 'secret_token',
}).then({response => {
window.axios.defaults.headers.common['Authorization'] = 'Bearer '+ response.data.access_token;
// Make call to /api/user
// ...
好的,所以我在这里检查了我的命名空间,并且我无法弄清楚Laravel是如何错过我创建的这个政策的:
axios.delete('/api/barracks/reply/delete/' + this.reply.id, { id: this.reply.id });
Route::delete('/barracks/reply/delete/{forumReply}','ForumRepliesController@destroy');
public function destroy(ForumReply $forumReply)
{
$this->authorize('destroy', $forumReply);
$forumReply->delete();
return response()->json(['Success',204]);
}
// ... Stuff
use App\ForumReply;
use App\Policies\ForumReplyPolicy;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
ForumReply::class => ForumReplyPolicy::class
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
// Passport Stuff
}
}
namespace App\Policies;
use App\User;
use App\ForumReply;
use Illuminate\Auth\Access\HandlesAuthorization;
class ForumReplyPolicy
{
use HandlesAuthorization;
public function destroy(User $user, ForumReply $forumReply)
{
return true;
}
}
我得到了Laravel的403回复,但对于我的生活,我找不到原因。
答案 0 :(得分:0)
对于任何访问此主题并使用web.php路由的人 - >中间件
我遇到的问题是该政策未在此行上调用:
Route::get('/post', 'PostController@index')
->middleware('can:index, App\Post');
问题是索引,App之间的空格字符。删除后它的作用。
答案 1 :(得分:0)
所以经过大量的游戏后,我发现了一个临时的解决方案,不幸的是有点难看。我已将其插入每个必要控制器的开头。
$user = \JWTAuth::toUser(\JWTAuth::getToken());
\Auth::loginUsingID($user->id);
然后我可以使用授权策略并检索经过身份验证的用户信息。