[SF3 - FOSREST - FOSUSER - FOSOAUT] probleme access API
Bonjour,
Je tourne en rond depuis plusieurs heures. Pour résumer simplement mon problème :
Je fais une première requête http post qui récupère bien le token
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| [root@dev-rcn httpdocs]# http POST url/oauth/v2/token \
> grant_type=password \
> client_id=3_3bcbxd9e24g0gk4swg0kwgcwg4o8k8g4g888kwc44gcc0gwwk4 \
> client_secret=4ok2x70rlfokc8g0wws8c8kwcokw80k44sg48goc0ok4w0so0k \
> username=admin \
> password=admin
HTTP/1.1 200 OK
Cache-Control: no-store, private
Connection: Keep-Alive
Content-Type: application/json
Date: Wed, 10 Aug 2016 08:52:00 GMT
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Server: Apache
Transfer-Encoding: chunked
X-Debug-Token: 50dd10
X-Debug-Token-Link:
X-Powered-By: PHP/5.6.19
{
"access_token": "N2M3M2M1OGI2OWEwN2U5NDM2ZWFhMGFiMjhmMWZhY2RiOGMzZjFhYjhlMzEyMDZkMjI3M2M3N2JkODcxNDk1ZQ",
"expires_in": 3600,
"refresh_token": "MzgwZTc3NmUzZGQzY2VhZTc3NWI2NzQ0YTU4ZjViMGFjZjBiYzI3MGU1YjczNjA0YjNiYThlMmZiMDhjODA0Mg",
"scope": null,
"token_type": "bearer"
} |
Et ensuite impossible de récupérer les données avec ce token
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| [root@vdev-rcn httpdocs]# http url/api/datas \ "Authorizat
ion:Bearer N2M3M2M1OGI2OWEwN2U5NDM2ZWFhMGFiMjhmMWZhY2RiOGMzZjFhYjhlMzEyMDZkMjI3M2M3N2JkODcxNDk1ZQ"
HTTP/1.1 401 Unauthorized
Cache-Control: no-store, private
Connection: Keep-Alive
Content-Type: application/json
Date: Wed, 10 Aug 2016 08:52:27 GMT
Keep-Alive: timeout=5, max=100
Pragma: no-cache
Server: Apache
Transfer-Encoding: chunked
WWW-Authenticate: Bearer realm="Service", error="access_denied", error_description="OAuth2 authentication required"
X-Debug-Token: 3ff60f
X-Debug-Token-Link:
X-Powered-By: PHP/5.6.19
{
"error": "access_denied",
"error_description": "OAuth2 authentication required"
} |
Et quand j’autorise les connexions anonymes ça fonctionne bien
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| [root@dev-rcn httpdocs]# http GET url/api/datas "Authorizatio
n:Bearer YTY1N2YxMDc0YzdiZmY0YjBlZjM0YWZiODY1NzhhMTNmY2RiNTU3Zjc3NjVlNDdiMDgwYjYyMzg0MjFiMmIxOQ"
HTTP/1.1 200 OK
Cache-Control: no-cache
Connection: Keep-Alive
Content-Type: application/json
Date: Wed, 10 Aug 2016 08:27:06 GMT
Keep-Alive: timeout=5, max=100
Server: Apache
Transfer-Encoding: chunked
X-Debug-Token: 9c9475
X-Debug-Token-Link:
X-Powered-By: PHP/5.6.19
{
"datas": [
{
"data01": "toto",
"data02": "titi",
"data03": "tutu",
"id": 1
},
{
"data01": "popo",
"data02": "pipi",
"data03": "pupu",
"id": 2
}
]
} |
voici ma conf
security.yml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| # To get started with security, check out the documentation:
security:
providers:
in_memory:
memory: ~
encoders:
FOS\UserBundle\Model\UserInterface: sha512
providers:
fos_userbundle:
id: fos_user.user_provider.username # fos_user.user_provider.username_email does not seem to work (OAuth-spec related ("username + password") ?)
firewalls:
oauth_token: # Everyone can access the access token URL.
pattern: ^/oauth/v2/token
security: false
api:
pattern: ^/api # All URLs are protected
fos_oauth: true # OAuth2 protected resource
stateless: true # Do no set session cookies
anonymous: false # Anonymous access is not allowed |
routing.yml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| api_tls:
resource: "@ApiTlsBundle/Controller/"
type: annotation
prefix: /
app:
type: rest
resource: "@ApiTlsBundle/Resources/config/routing_api.yml"
fos_user:
resource: "@FOSUserBundle/Resources/config/routing/all.xml"
NelmioApiDocBundle:
resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
prefix: /info/doc
fos_oauth_server_token:
resource: "@FOSOAuthServerBundle/Resources/config/routing/token.xml" |
config.yml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| nelmio_api_doc: ~
fos_user:
db_driver: orm
firewall_name: api
user_class: ApiTlsBundle\Entity\User
# FOSRestBundle
fos_rest:
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: 'force'
formats:
xml: true
json : true
templating_formats:
html: true
force_redirects:
html: true
failed_validation: HTTP_BAD_REQUEST
default_engine: twig
routing_loader:
default_format: json
include_format: false
fos_oauth_server:
db_driver: orm
client_class: ApiTlsBundle\Entity\Client
access_token_class: ApiTlsBundle\Entity\AccessToken
refresh_token_class: ApiTlsBundle\Entity\RefreshToken
auth_code_class: ApiTlsBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager |
Ça parle a quelqu’un ce genre de problème ? hellllp