Comments (6)
@Lbatson I'm using Plug 1.0.2 and Guardian 0.6.2 together without issue.
As for the tuple, I'm pretty sure Guardian assigns that value. See plug.ex#L139 & plug_test.exs#L13
from guardian.
@doomspork it still fails for me. are you using Guardian.Plug.claims
anywhere? I always end up getting the :no_session
error even though i can see the claims in then conn
itself. I did fix the issue with it failing on EnsureAuthenticated
which had an issue with my on_verify hook failing, however I've noticed that Guardian.Plug.VerifyHeader
also always fails with :no_session
as well but then verifies the token and adds it. https://github.com/hassox/guardian/blob/master/lib/guardian/plug/verify_header.ex#L49
Also, not sure if it's relevant or not but i'm using Erlang 18 and Elixir 1.1.1
from guardian.
Ok, think i've found the issue. The way VerifyHeader
and api_sign_in
set claims is different. VerifyHeader
attaches a tuple, https://github.com/hassox/guardian/blob/master/lib/guardian/plug/verify_header.ex#L63, where api_sign_in
simply adds the claims, https://github.com/hassox/guardian/blob/master/lib/guardian/plug.ex#L171. This means if you call Guardian.Plug.claims
on the conn
after api_sign_in
, for instance in the after_sign_in
hook, it will fail as Guardian.Plug.claims
looks for the tuple, doesn't get it and gives the :no_session
error. I think to fix this it should just be one or the other wins out, setting as a tuple or just the claims. Not sure what approach is wanted or what else it might affect yet but fixing the inconsistency would solve this.
from guardian.
Hey @Lbatson I'm also on Erlang 18 and Elixir 1.1.1. Unless I'm reading the @spec
wrong the claims are always a tuple. If you look at the method you linked to in Plug you'll see the spec define the claims parameter as being a tuple:
@spec set_claims(Plug.Conn.t, { :ok, Map }, atom) :: Plug.Conn.t
I suspect there might be some other configuration you're missing. Is your project on GitHub? I recently updated the Guardian sample project to the latest dependencies, have you looked at that? My changes are in a PR here: phoenix_guardian/pull/5
from guardian.
The @spec
does shows the tuple, however the parameter passed to set_claims
from api_sign_in
is just the Map
. Maybe it should be changed to |> set_claims({:ok, full_claims}, the_key)
or instead of setting a tuple to the claims just set the claims themselves and modify the other portions that use it with the tuple?
from guardian.
@Lbatson looks like you're right. I've been using Guardian.decode_and_verify(jwt)
which the Guardian tests use and that seems to work. Once I updated my code to use Guardian.Plug.claims
I was able to repo your issue. While I was looking into the api_sign_in
I found another issue so I'll open a PR for both.
from guardian.
Related Issues (20)
- Compilation error in file guardian.ex: type options/0 undefined HOT 1
- Is guardian relying on JWT's fixed side ? HOT 2
- Provide a way to retrieve verifying secret at runtime using connection information
- Help with EnsureNotAuthenticated HOT 1
- Successfully validates a JWT token with a timestamp in the past
- use Bitwise is deprecated in elixir 1.14-dev
- Warning causing compile error with Elixir 1.14.0 HOT 1
- Unable to set secret_key in runtime.exs HOT 12
- changelog is missing in the doc HOT 1
- all_permissions? function returns true even if permission set given is not within the list of permissions provided and compiled
- I would like to be able to set permissions from a DB table rather than hard coded in a permissions set. HOT 8
- guardian.encode_and_sign 1st argument: not an atom HOT 1
- Opaque errors when token verification fails HOT 3
- Using an environment variable as a secret key in elixir 1.14 HOT 2
- Breaking Change on 2.3.1 - Can't encode Bitwise Permissions HOT 6
- Generating a JWT with kty=oct can fail because of incorrect Base64 encoding
- after_encode_and_sign result not used HOT 2
- Move to Elixir 1.14 and otp 25 HOT 3
- system_time vs os_time and time drift HOT 1
- refresh_from_cookie only accepts "default" as key HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from guardian.