symfonyoauth-2.0hwioauthbundlefosoauthserverbundle

What HWIOAuthBundle is expecting from the infos_url?


I am trying to config my oauth2 server with HWIOAuthBundle and I would like to have some clarifications on what HWIOAuthBundle is expecting as response to config correctly infos_url?

I guess it is expecting a json file. So, what are its fields? If you have links, I will be happy.

hwi_oauth:
    firewall_name: main
    resource_owners:
        battlenet:
            type: oauth2
            client_id: "%client_id%"
            client_secret: "%client_secret%"
            access_token_url: %path%/oauth/token
            authorization_url:  %path%/oauth/authorize
            infos_url:  %path%/user/me
            scope: "read"
            user_response_class: HWI\Bundle\OAuthBundle\OAuth\Response\PathUserResponse
            paths:
                identifier: id
                nickname: id
                realname: id

Thanks ;)


Solution

  • I found how it can be done! You have to create a simple API for the users as follows:

    The routing:

    # app/routing.yml
    api_users:
        pattern: /api/users.json
        defaults: { _controller: AppOAuthServerBundle:User:getUser }
        options:
            i18n: false
    

    The controller:

    <?php
    namespace App\OAuthServerBundle\Controller;
    
    use App\GeneralBundle\Entity\User;
    use FOS\RestBundle\Controller\FOSRestController;
    
    class UserController extends FOSRestController
    {
        public function getUserAction()
        {
            $user = $this->get('security.context')->getToken()->getUser();
    
            if ( $user instanceof User ) {
    
                $data = array(
                    'id' => $user->getId(),
                    'username' => $user->getUsername(),
                    'realname' => $user->getFirstname().' '.$user->getLastname(),
                    'email'    => $user->getEmail(),
    
                );
            } else {
                $data = array();
            }
    
    
            $view = $this->view($data, 200)
                ->setTemplate('AppOAuthServerBundle:Default:index.html.twig')
                ->setFormat('json')
                ->setTemplateVar('user');
    
            return $this->handleView($view);
        }
    }