GithubHelp home page GithubHelp logo

Comments (7)

naveen1941 avatar naveen1941 commented on May 12, 2024 5

Hey @driesvints, i've noticed a strange bug when writing unit tests for logout. My logout() method is the same as described above.

Test code => https://pastebin.com/LZ7wMgeg

Response i get:
{"message":"Call to undefined method Laravel\\Sanctum\\TransientToken::delete()","errors":null}

Weird thing here is that route actually works when you call it from Postman/Application, but test fails. Maybe i am doing something wrong ?

I am also facing the same issue.

from sanctum.

Sporium avatar Sporium commented on May 12, 2024 3

In my case

{"message":"Call to undefined method Laravel\Sanctum\TransientToken::delete()","errors":null}

error was because of EnsureFrontendRequestsAreStateful::class in app/Http/Kernel.php 'api' section.
As i found out (hope Im not wrong) when you include EnsureFrontendRequestsAreStateful middware Laravel try to authenticate you using CSRF token not bearerToken. And because in

vendor/laravel/sanctum/src/Guard.php

this guard check is prior you create new TransientToken.
When you try to user()->currentAccessToken()->delete() it fails by trying to call delete() from TransientToken.
But if you want to delete bearer Token its in PersonalAccessToken
so you can PersonalAccessToken::findToken($request->bearerToken())->delete(); but this looks wrong:)
If you use Mobile Application Authentication you can simply remove EnsureFrontendRequestsAreStateful and this will fix problem.
If you want to use that middelware:
This issue can be fixed just moving this lines https://github.com/laravel/sanctum/blob/2.x/src/Guard.php#L54-L58
below this https://github.com/laravel/sanctum/blob/2.x/src/Guard.php#L60-L75
If this structure not critical that helps with this problem (or we need something to chose what token we want to use)
Also to revoke CSRF token use $request->session()->invalidate();

from sanctum.

Dzale avatar Dzale commented on May 12, 2024 2

Hey @driesvints, i've noticed a strange bug when writing unit tests for logout. My logout() method is the same as described above.

Test code => https://pastebin.com/LZ7wMgeg

Response i get:
{"message":"Call to undefined method Laravel\\Sanctum\\TransientToken::delete()","errors":null}

Weird thing here is that route actually works when you call it from Postman/Application, but test fails. Maybe i am doing something wrong ?

from sanctum.

icedevbug avatar icedevbug commented on May 12, 2024 1

The Bearer prefix must be added to the Header Authorization
axios.defaults.headers.Authorization = "Bearer " + token;

from sanctum.

driesvints avatar driesvints commented on May 12, 2024

Heya, feel free to send in a PR if you want.

from sanctum.

jerearaujo03 avatar jerearaujo03 commented on May 12, 2024

I'm getting the same

from sanctum.

masihfathi avatar masihfathi commented on May 12, 2024

do you find any valid solution to this issue? i want use spa and http authentication with the same code but i got error in user()->currentAccessToken()->delete(),also i use EnsureFrontendRequestsAreStateful middleware

from sanctum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.