php - Symfony HWIOAuthBundle Accesstoken -
i need access token on social network, example github. logic when authentication user enter in profile can put button , confirm account social network , situation need access token access token oauth. have standard registration , authentication , need access token , set 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 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 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 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 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 have error
unable generate url named route "hwi_oauth_connect_service" such route not exist. stack
in app/cache/dev/appdevurlgenerator.php @ line 259 - public function generate($name, $parameters = array(), $referencetype = self::absolute_path) { if (!isset(self::$declaredroutes[$name])) { throw new routenotfoundexception(sprintf('unable generate url named route "%s" such route not exist.', $name)); } list($variables, $defaults, $requirements, $tokens, $hosttokens, $requiredschemes) = self::$declaredroutes[$name]; how can token ?
solved
when add routkng in bundle routing solved 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 have when connect git hub have enter in rout in hwi_oauth_connect_service action: connectserviceaction , have standard template, how reload controller , action , change template ?? or how after service app.provider.user_provider make redirect in routing?
a example of hwioauthbundle implementation fosuserbundle https://gist.github.com/danvbe/4476697
edit
hwioauthbundle bundle oauth provides great documentation configuration/usage.
first, have set firewall on hwioauth used. should same your
then, have register symfony2 application on social network connect users.
when it's done, in bundle configuration, add social network credentials (application id + token) provided social network). see configuring resource owners doc.
after that, authenticate users on social network , access token, have connect user provider hwioauthbundle.
the first link show how make hwioauthbundle working fosuserbundle user provider. can adapt needs setting own user provider , skip step fosub.
there lot of examples such hwioauthbundlebyexample show how use basic user provider.
: adding hwioauthbundle symfony2 project
this bundle based on configuration, not rewrite bundle documentation here.
edit2
you must have following in routing :
hwi_oauth_login: resource: "@hwioauthbundle/resources/config/routing/login.xml" prefix: /login hwi_oauth_redirect: resource: "@hwioauthbundle/resources/config/routing/redirect.xml" prefix: /connect hwi_oauth_connect: resource: "@hwioauthbundle/resources/config/routing/connect.xml" prefix: /connect # ... add other routes here
Comments
Post a Comment