0
I am using the Standard Sanctum to generate access tokens for my api. I have followed the step-by-step documentation of the Standard. I generated a token. But when I go to access a route that contains a middleware auth:sanctum
com in the documentation gives a 401 error stating that it is not authorized. Even if I pass the token as Header Authorization Bearer. I followed step by step but I can’t find the problem.
Code for token generation
if($this->validator($data)){
$user = $this->create($data);
$token = $user->createToken('acesso',['tipo:'.$user->tipo]);
return $token->plainTextToken;
}` Rota no Arquivo api.php `Route::middleware('auth:sanctum')->get('/users',"UserController@users");` Código da requisição com axios `var token = "aeeeabab01978e8edfcba40f523f54b424c2d956e1dfbf856049ad9311241087";
axios
.get("/api/users",
{ headers: { Authorization: `Bearer: ${token}`} })
.then(response => {
// If request is good...
console.log(response.data)
});
Which route are you using? would be .../api/broadicasting/auth ? I’m doing with Laravel Echo Server and I can’t access a Privatechannel or Presencechannel, only working with Channel(). Could you share your experience?
– Cleber Martins
After I discovered my mistake, I realized I didn’t need to build an api. So I started to define the data routes in the web.php file and I use Laravel’s default authentication. I’m also using Laravel Echo. I was able to access all kinds of channels, but with Laravel’s standard authentication. What type of authentication to access your application ("Other than the API"), you are using?
– Renan Rodrigues
Could you share an example of this implementation?
– Jean Freitas