I need to get access token on social network, example github. The logic is when my authentication user enter in profile he can put button and confirm account with social network and this situation I need access token access token oauth. I have standard registration and authentication and only I need this is get access token and set it in DB.
I install bundle write in kernel
"hwi/oauth-bundle": "0.4.*@dev"
new HWI\Bundle\OAuthBundle\HWIOAuthBundle(),
my config:
hwi_oauth:
connect:
account_connector: app.provider.user_provider
firewall_name: secured_area
resource_owners:
github:
type: github
client_id: "%github_app_id%"
client_secret: "%github_app_secret%"
scope: "user,public_repo"
and my routing:
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /connect
hwi_oauth_login:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login
github_login:
path: /login/check-github
and routnig in bundle
hwi_oauth_security:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /login
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /login
and my security:
firewalls:
secured_area:
anonymous: ~
oauth:
resource_owners:
github: "/login/check-github"
login_path: /login
use_forward: false
failure_path: /login
oauth_user_provider:
service: app.provider.user_provider
and config for service:
<parameters>
<parameter key="my_user_provider.class">Artel\ProfileBundle\Providers\UserProvider</parameter>
</parameters>
<service id="app.provider.user_provider" class="%my_user_provider.class%">
<argument type="collection">
<argument key="github">githubId</argument>
</argument>
<call method="setGithubProvider">
<argument type="service" id="geekhub.user.github_provider" />
</call>
</service>
class UserProvider implements OAuthAwareUserProviderInterface
{
/**
* {@inheritDoc}
*/
public function connect(UserInterface $user, UserResponseInterface $response)
{
//I think this I get access token in request
}
/**
* {@inheritdoc}
*/
public function loadUserByOAuthUserResponse(UserResponseInterface $response)
{
}
and in template
<a class="logo" href="{{ path('hwi_oauth_service_redirect', {'service' : 'github'}) }}">Gh</a>
but I have error
Unable to generate a URL for the named route "hwi_oauth_connect_service" as such route does not exist.
stack
in app/cache/dev/appDevUrlGenerator.php at line 259 -
public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH)
{
if (!isset(self::$declaredRoutes[$name])) {
throw new RouteNotFoundException(sprintf('Unable to generate a URL for the named route "%s" as such route does not exist.', $name));
}
list($variables, $defaults, $requirements, $tokens, $hostTokens, $requiredSchemes) = self::$declaredRoutes[$name];
How can I just get a token ?
SOLVED
when I add routkng in bundle routing I solved this problem
hwi_oauth_security:
resource: "@HWIOAuthBundle/Resources/config/routing/login.xml"
prefix: /login
hwi_oauth_connect:
resource: "@HWIOAuthBundle/Resources/config/routing/connect.xml"
prefix: /login
hwi_oauth_redirect:
resource: "@HWIOAuthBundle/Resources/config/routing/redirect.xml"
prefix: /login
But now I have another when I connect to git hub I have enter in rout in hwi_oauth_connect_service action: connectServiceAction and have standard template, how to reload this controller and action and change template ?? Or how after service app.provider.user_provider make redirect in my routing?