duanrenzou1619 2013-11-13 14:09
浏览 103
已采纳

oauth2-php库客户端授权

I'm using the oauth2-php library hosted on Google code. I'm confused on the example code and specifically how to go from the addClient.php page to the authorize.php page.

Currently, I enter some credentials in the <form> on the addClient.php page, which are correctly INSERTed into to my database. Unfortunately, when I point the browser to the authorize.php page I get the following error:

{"error":"invalid_client"}

Might someone help me understand why authorize.php isn't pulling my client data from my database?

  • 写回答

1条回答 默认 最新

  • duanlinzhen7235 2013-11-13 14:47
    关注

    In order to access a protected resource with a given example code:

    1) Create a client (provide client id, client secret, redirect uri):

    /addclient.php
    

    2) Fetch auth code from authorization server:

    /authorize.php?client_id=foo&response_type=code
    

    It will redirect you to the redirect uri specified in step 1 adding code as a GET parameter.

    3) Do a POST request to get access token:

    /token.php 
    

    with post params:

    grant_type=code&client_id=foo&code=[AUTH_CODE_FROM_STEP_2]&client_secret=[SECRET]&redirect_‌​uri=[REDIRECT_URI_FROM_STEP_1]
    

    It will give you JSON with access_token in it.

    4) Fetch protected resource (oauth_token can be passed both as GET or POST param)

    /protected_resource.php?oauth_token=[ACCESS_TOKEN_FROM_STEP_3] 
    

    Also I don't know if you're dealing with some legacy code, but this lib is outdated as it is based on 09 (draft) version of oauth 2. There are implementations referenced on the official page http://oauth.net/2/ which are up to date. You may want to take a look at them.

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

报告相同问题?

悬赏问题

  • ¥200 csgo2的viewmatrix值是否还有别的获取方式
  • ¥15 Stable Diffusion,用Ebsynth utility在视频选帧图重绘,第一步报错,蒙版和帧图没法生成,怎么处理啊
  • ¥15 请把下列每一行代码完整地读懂并注释出来
  • ¥15 pycharm运行main文件,显示没有conda环境
  • ¥15 寻找公式识别开发,自动识别整页文档、图像公式的软件
  • ¥15 为什么eclipse不能再下载了?
  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上