我正在将FOSOAuthBundle与FOSUserBundle一起用于移动应用程序等使用的API。我正在尝试使用访问令牌访问某些用户配置文件信息以查找用户详细信息,但是未设置user_id。
<?php
namespace MyBundle\ApiBundle\Entity;
use FOS\OAuthServerBundle\Entity\AccessToken as BaseAccessToken;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class AccessToken extends BaseAccessToken
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="Client")
* @ORM\JoinColumn(nullable=false)
*/
protected $client;
/**
* @ORM\ManyToOne(targetEntity="MyBundle\UserBundle\Entity\User")
*/
protected $user;
}
更多信息,我正在遵循您的文档中的教程。这是我的安全:
# app/config/security.yml
security:
encoders:
FOS\UserBundle\Model\UserInterface: sha512
role_hierarchy:
ROLE_USER: ROLE_USER
ROLE_ADMIN: ROLE_ADMIN
ROLE_SUPER_ADMIN: ROLE_ADMIN
providers:
fos_userbundle:
id: fos_user.user_provider.username
firewalls:
main:
pattern: ^/
form_login:
provider: fos_userbundle
csrf_provider: form.csrf_provider
logout: true
anonymous: true
oauth_token:
pattern: ^/oauth/v2/token
security: false
oauth_authorize:
pattern: ^/oauth/v2/auth
security: true
form_login:
provider: fos_userbundle
check_path: /oauth/v2/auth/login_check
login_path: /oauth/v2/auth/login
api:
pattern: ^/api
fos_oauth: true
stateless: true
anonymous: false # can be omitted as its default value
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: ^/api$, role: IS_AUTHENTICATED_FULLY }
- { path: ^/checkout$, role: IS_AUTHENTICATED_FULLY }
这是UserBundle和oAuthBundle的配置设置:
# app/config/config.yml
fos_user:
db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
firewall_name: main
user_class: PremierParkingLogistics\UserBundle\Entity\User
# app/config/config.yml
fos_oauth_server:
db_driver: orm # Driver availables: orm, mongodb, or propel
client_class: PremierParkingLogistics\ApiBundle\Entity\Client
access_token_class: PremierParkingLogistics\ApiBundle\Entity\AccessToken
refresh_token_class: PremierParkingLogistics\ApiBundle\Entity\RefreshToken
auth_code_class: PremierParkingLogistics\ApiBundle\Entity\AuthCode
service:
user_provider: fos_user.user_manager
我正在关注本指南:https://github.com/FriendsOfSymfony/FOSOAuthServerBundle/blob/master/Resources/doc/index.md
任何帮助或指向正确的方向,都将非常感激!
答案 0 :(得分:2)
请确保在请求令牌时将grant_type设置为密码。