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

Allow credentials to be sent as JSON #123

Closed
flo-sch opened this issue Jan 10, 2016 · 3 comments
Closed

Allow credentials to be sent as JSON #123

flo-sch opened this issue Jan 10, 2016 · 3 comments

Comments

@flo-sch
Copy link

flo-sch commented Jan 10, 2016

Hi,

Thanks for this bundle, it works great so far :)

I was just wondering, would it be possible to allow credentials to be sent both a a JSON object or application/x-www-form-urlencoded data?

It just makes more sense, as the response is sent in the JSON format anyway.
Basically, in addition to this request:

POST /api/login HTTP/1.1
Host: https://whatever.domain.org

_username="any-name"&_password="any-password"

Allow this one also:

POST /api/login HTTP/1.1
Host: https://whatever.domain.org
Content-Type: "application/json"

{
    "_username": "any-name",
    "_password": "any-password"
}
@slashfan
Copy link
Contributor

Hi,

I don't think that's the bundle's role to handle the request format. Currently all examples are based on the form_login provided by Symfony wich expects application/x-www-form-urlencoded, so if you want to keep using it you will have to implement a request listener which will convert your json payload to the appropriate format. FOSRestBundle provides such a listener.

Hope it helps !

@flo-sch
Copy link
Author

flo-sch commented Jan 22, 2016

Oh, okay, I just did not know it would work with a RequestListener!
Thanks, I'll carry it myself so :)

@dunglas
Copy link

dunglas commented Jun 2, 2016

See symfony/symfony#18952

fabpot added a commit to symfony/symfony that referenced this issue Dec 3, 2016
This PR was squashed before being merged into the 3.3-dev branch (closes #18952).

Discussion
----------

[Security] Add a JSON authentication listener

| Q | A |
| --- | --- |
| Branch? | master |
| Bug fix? | no |
| New feature? | yes |
| BC breaks? | no |
| Deprecations? | no |
| Tests pass? | yes |
| Fixed tickets | n/a |
| License | MIT |
| Doc PR | symfony/symfony-docs#7081 |

Add a new authentication listener allowing to login by sending a JSON document like:

 `{"_username": "dunglas", "_password": "foo"}`.

It is similar to the traditional form login (but take a JSON document as entry) and is convenient for APIs, especially used in combination with JWT.

See api-platform/core#563 and lexik/LexikJWTAuthenticationBundle#123 (comment) for previous discussions.
- [x] Add functional tests in security bundle

Commits
-------

02178bc [Security] Add a JSON authentication listener
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

3 participants