Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve User from given Token, from an unsecured path #62

Closed
Ph3nol opened this issue Apr 16, 2015 · 4 comments
Closed

Retrieve User from given Token, from an unsecured path #62

Ph3nol opened this issue Apr 16, 2015 · 4 comments

Comments

@Ph3nol
Copy link

Ph3nol commented Apr 16, 2015

Hi,

First congrats for this awesome and amazing bundle that I'm currently using for all my WebServices projects.

My little question:
What is the best way to retrieve a user from an unsecured path?

My context:
I have a /api/1/example/{id}.json endpoint, to access an element informations.
This path is unsecured.
I'd like to use an optional token, and retrieve matching user if passed through the Request headers.
The problem is that without passing through the firewall (and so the bundle security listener), my token-user association is not handled.

Any idea about this?

Thank you so much.

@slashfan
Copy link
Contributor

Hi,

I think you could use the JWTManager::decode(TokenInterface $token) method.
Unfortunately it only accepts a TokenInterface so you would have to first create a new JWTUserToken and pass it your token in the setRawToken($rawToken) method.

If the token is successfully decoded it will return an array containing the user identity (by default the username). Then it's up to you to retrieve your user from it.

Of course, it's all theory ! Let me know if it works :)

@Ph3nol
Copy link
Author

Ph3nol commented Apr 17, 2015

I was thinking about using this solution yesterday, but ignoring if a better practice was planned for an incoming release.

I'll test it today and keep you informed about it.
Thanks! :)

@Ph3nol
Copy link
Author

Ph3nol commented Apr 17, 2015

I confirm this theory works perfectly! :)

@Ph3nol Ph3nol closed this as completed Apr 17, 2015
@slashfan
Copy link
Contributor

Great :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants