doulan8330 2015-05-02 01:36
浏览 137

使用php在twitch.tv中进行OAuth身份验证

I've seen similar Questions like this before but don't understand the correct way of doing it. Or rather the questions were always a little different.

The scenario: I have a site where the user should log in via twitch.tv I have a button which refers him to this url

https://api.twitch.tv/kraken/oauth2/authorize?response_type=code
    &client_id=exampleclientid
    &redirect_uri=http://example.com
    &scope=user_read

I have censored redirect_uri and the client_id but basicly on this site the user needs to login into twitch or if he already is he can authorize that my application gets acess to "scope" here in this case "user_read" which is his email adress.

Now to my problem. When returning to my site my url will look like this

example.com/#access_token=exampleacesstoken&scope=user_read

example acess token is just a combination of numbers and letters which I need to acess private information like his email even his username.

Over this url

https://api.twitch.tv/kraken?oauth_token=exampletoken

I get acess to my needed information, but how do I grab the token from my url via php and delete everything after http://example.com to make it look good again.

The offical API documentation might be helpful and talks about CURL but I don't understand how it works and the PHP manual is very indepth.

https://github.com/justintv/Twitch-API

Sorry if I'm taking the lazy way here, but I think I'm missunderstanding something big because I just have to make a simple grab of the URL

  • 写回答

1条回答 默认 最新

  • douyao3895 2015-05-02 02:19
    关注

    From the Twitch documentation:

    https://github.com/justintv/Twitch-API/blob/master/authentication.md#implicit-grant-flow

    If the user authorizes your application, they will be redirected to the following URL:

    https://[your registered redirect URI]/#access_token=[an access token]&scope=[authorized scopes]

    Note that the access token is in the URL fragment, not the query string, so it won't show up in HTTP requests to your server. URL fragments can be accessed from JavaScript with document.location.hash.

    评论
    编辑
    预览

    报告相同问题?

    手机看
    程序员都在用的中文IT技术交流社区

    程序员都在用的中文IT技术交流社区

    专业的中文 IT 技术社区,与千万技术人共成长

    专业的中文 IT 技术社区,与千万技术人共成长

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

    客服 返回
    顶部