简体   繁体   English

自动获取签名的请求令牌

[英]Automatically get signed request token

From my understanding of OAuth, the flow is: 根据我对OAuth的了解,流程为:

  1. Get unsigned request token 获取未签名的请求令牌
  2. Get signed request token by getting user authorization 通过获得用户授权来获取签名的请求令牌
  3. Get access token 获取访问令牌

I would like to use php curl to get the signed request token automatically. 我想使用php curl自动获取签名的请求令牌。 Once I have the unsigned request token, I'd like a function to go to authorization url, sign in and return the authorized request token. 拥有未签名的请求令牌后,我想要一个函数转到授权url,登录并返回授权的请求令牌。 Basically mimicking basic authorization with username and password. 基本上模仿使用用户名和密码的基本授权。 Is this possible? 这可能吗?

I understand it can't be a general solution since the curl postdata will have to be specific to the site. 我知道这不是一个通用的解决方案,因为curl postdata必须特定于该站点。

Thanks 谢谢

Here's some code and I hope it helps to show you what I'm trying to do. 这是一些代码,我希望它有助于向您展示我正在尝试做的事情。

function login($username, $password) {
    $url = 'https://www.scoop.it/oauth/authorize?' . http_build_query(array('oauth_token' => $requestToken['oauth_token'], 'oauth_callback' => $callbackurl));

    $postdata = "email=".$username."&password=".$password; 

    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);   
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);


    $response = curl_exec($ch)
    curl_close ($ch);
}

Your script needs to: 您的脚本需要:

  1. fetch an unauthorized request token 获取未授权的请求令牌
  2. redirect the user to authorization URL with the token and callback URL 使用令牌和回调URL将用户重定向到授权URL

You already completed step 1; 您已经完成了步骤1; fetching the access token. 获取访问令牌。 Now you must tell the user's browser to redirect to authorization URL. 现在,您必须告诉用户的浏览器重定向到授权URL。

header('HTTP/1.1 301 Moved Permanently');
header('Location: '.$AUTHORIZE_URL_WITH_TOKEN);

And remember, you have to send out all headers before the first print() or echo() that ever happens. 记住,您必须在发生第一个print()echo()之前发送所有标头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM