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.

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

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀