我正在尝试使用FOSOAuthServerBundle。
从我的ios应用程序中,我正确地从/oauth/v2/token中获得令牌,我可以在我的数据库中看到AccessToken和RefreshToken中的条目具有正确的user_id。
打开_profile,我可以看到我的身份验证,但我登录为匿名…为什么会这样?
当尝试访问/secure/api/me时,我被重定向到/login path…
有人能帮帮我吗?
Here my security.yml
security:
encoders:
FOSUserBundleModelUserInterface: sha512
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: ROLE_USER
providers:
fos_userbundle:
id: fos_user.user_provider.username_email
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
# form_login:
# provider: fos_userbundle
# check_path: /oauth/v2/auth_login_check
# login_path: /oauth/v2/auth_login
anonymous: true
api:
pattern: ^/api
fos_oauth: true
stateless: true
anonymous: true
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
login_path: /login
check_path: /login_check
oauth:
resource_owners:
facebook: "/login/check-facebook"
google: "/login/check-google"
login_path: /login
use_forward: false
failure_path: /login
oauth_user_provider:
#this is my custom user provider, created from FOSUBUserProvider - will manage the
#automatic user registration on your site, with data from the provider (facebook. google, etc.)
service: my_user_provider
logout: true
anonymous: true
login:
pattern: ^/login$
security: false
remember_me:
key: "%secret%"
lifetime: 31536000 # 365 days in seconds
path: /
domain: ~ # Defaults to the current domain from $_SERVER
access_control:
- { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin/, role: ROLE_ADMIN }
- { path: ^/oauth/v2/auth, role: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/secured, role: [ IS_AUTHENTICATED_FULLY ] }
.
我想你有在你的安全。Yml,在防火墙下'api ':
//...
api :
// ...
stateless : true
// ...
您必须在每个请求上发送access_token。
此外,如果您想要获得一个经过身份验证的access_token,您必须通过带参数"grant_type=password"的请求来获得它。使用这个access_token,您的服务器将在每个请求中识别用户。
类似:PROVIDER_HOST/oauth/v2/令牌? client_id = CLIENT_ID& client_secret = CLIENT_SECRET& grant_type = password&密码用户名= USERNAME&密码=
(来源:OAuth2解释:第3部分-徒手使用OAuth2)