1

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 ;)

Amine Jallouli
  • 3,919
  • 8
  • 36
  • 73
  • I think it is for user public profile fields. – malcolm Sep 04 '16 at 09:41
  • BTW did you heard abou this bundle https://github.com/knpuniversity/oauth2-client-bundle with guard authentication, you can write your custom provider as well. – malcolm Sep 04 '16 at 09:46

1 Answers1

2

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);
    }
}
Amine Jallouli
  • 3,919
  • 8
  • 36
  • 73