doukong6031 2015-04-10 03:33
浏览 61

使用symfony2创建一个oauth2客户端

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

  • 写回答

1条回答 默认 最新

  • duanhuantong8278 2015-04-10 06:07
    关注

    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

    评论

报告相同问题?