ios - FOSOAuthServerBundle - generate manually an access token -
i have symfony2 website , web service secured via oauth using fosoauthserverbundle accessible via ios app. on website use fosuserbundle , fosfacebookbundle.
the thing miss giving possibility user login facebook on ios app , return him access_token oauth linked user account can access api other users.
so want send user facebookid , facebook_access_token webservice, check user correct (token matches app) , return authentication token.
question: there easy way add "facebook" grant_type fosoauthserverbundle ?
i know people have done seeing these questions:
design facebook authentication in ios app accesses secured web service
get application id user access token (or verify source application token)
but not explain how, not seem use fosoauthserverbundle , questions quite old.
i have tried using bundle: https://github.com/thefootballsocialclub/fscoauth2facebookgrantbundle
but bundle has been downloaded 9 times before me , not suited app (it considers facebook user username equals facebookid instance). guess want re-implement same kind of thing own way.
if has done our provide guidance appreciated.
thank you
to this, have add grant extensions, see official document "adding grant extensions" : https://github.com/friendsofsymfony/fosoauthserverbundle/blob/master/resources/doc/adding_grant_extensions.md
you can find facebookgrantextension token fb access_token :
class facebookgrantextension implements grantextensioninterface { protected $usermanager = null; protected $facebooksdk = null; public function __construct(usermanager $usermanager, \basefacebook $facebooksdk) { $this->usermanager = $usermanager; $this->facebooksdk = $facebooksdk; } /** * @see oauth2\ioauth2grantextension::checkgrantextension */ public function checkgrantextension(ioauth2client $client, array $inputdata, array $authheaders) { if (!isset($inputdata['facebook_access_token'])) { return false; } $this->facebooksdk->setaccesstoken($inputdata['facebook_access_token']); try { // try user facebook token open graph $fbdata = $this->facebooksdk->api('/me'); if (empty($fbdata) || !isset($fbdata['id'])) { return false; } // check if user match in database facebook id $user = $this->usermanager->finduserby(array( 'facebookid' => $fbdata['id'] )); // if no user found, register new user , grant token if (null === $user) { return false; } // else, return access_token user else { return array( 'data' => $user ); } } catch(\facebookapiexceptionion $e) { return false; } } }
and config.yml :
my.oauth.facebook_extension: class: my\corebundle\oauth\facebookgrantextension arguments: usermanager: "@fos_user.user_manager" facebooksdk: "@fos_facebook.api" tags: - { name: fos_oauth_server.grant_extension, uri: 'http://grants.api.mywebsite.com/facebook_access_token' }
Comments
Post a Comment