doucha5080 2016-06-29 10:53
浏览 70
已采纳

使用PHP登录OAuth2

So I am creating a website to learn some PHP/Javascript/HTML/CSS and so on and I ran into a problem to which I can't come up with a solution. So basically I have regular login form using PHP which uses POST to send the data and authenticate. I also want to integrate external Twitch.tv OAuth2 authentication.

By using normal PHP login I store my information inside PostgreSQL database using php. I want to do something similar using OAuth2. For example store Twitch.tv name as a username inside the database and token as a password.

The problem is that the external authentication I am using is based on their Javascript API and it stores the information inside the DOM storage which I found is unable to be access by using PHP. The redirect_uri with a token is also a fragment which can't be retrieved by PHP.

Should I just scrap the JS part and try doing it entirely in PHP?

Side question: I checked other website which also uses Twitch authentication and it uses these callback links "https://api.nightbot.tv/auth/twitch/callback?code=****". What exactly are these callbacks?

  • 写回答

1条回答 默认 最新

  • dragon5006 2016-06-29 11:09
    关注

    You should use redirects as you implied with JS frameworks. It works the same with Facebook. The redirects are used with a token. Usually you generate on your side a random token that you store in the session. Once the user logs in using the JS API, the API will redirect to a callback page (PHP in your case). In that page, you verify the token once (that you had passed and got back, must be the same), and also you get another token from the API to use with the API. At this point you can get the user information by querying the API using the API token. You get the user info from the API and then you can query your down DB at this point to log the user in etc. I hope this helps..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?