简体   繁体   中英

Make an oauth2 client with symfony2

I made a oauth2 server, and now I want to make c client using symfony2 to connect to it (when I click login, I'm redirected on the site with oauth2 server, I login, then I'm redirected to my client with the token).

I followed this: http://symfony.com/doc/current/cookbook/security/api_key_authentication.html

The problem is whem they retrieve the apikey. If I decide to use implicit grant with oauth2, the token is sent like that: example.com/#token So I can't retrieve it with query->get. If I send the code it's fine, but when I tried to curl my server somehow it broke (yeah, not specific error, still looking into it)

So I was wondering, is this the proper way of doing it?

Also, when they write about he specific url, why would I need one, if I can check everywhere?

Thanks :)

you can get your token like this in php :

For known url if you have your url with the hash, this part after # is called fragment.

$url=parse_url($yoururl);
echo $url["fragment"];

if you don't have this url in your backend, you need some javascript magic :

var token = window.location.hash;

then send it to your backend.

Maybe there is some other more symfonyc way to do this properly, but i never used oauth2 yet.. :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM