【问题标题】:Podio PHP API authenticationPodio PHP API 认证
【发布时间】:2018-10-11 11:36:07
【问题描述】:

我对 Podio PHP API 身份验证有疑问。如果没有以下致命错误,我将无法完成某些事情。我这样做:Podio::authenticate_with_password('aaa', 'bbb');

我明白了:PHP Fatal error: Uncaught PodioRateLimitError: "You have hit the rate limit. Please wait 300 seconds before trying again"

我的系统处理分布在许多空间中的复杂关系,这就是为什么我创建了一个“主”帐户,该帐户在每个目标空间中都具有管理员角色。

每次调用 webhook 时,我都会使用“主”帐户进行身份验证(由于同一脚本中存在多个关系,因此使用应用进行身份验证需要大量工作)。

同一个 webhook 被多次调用,但在不同的上下文中。

如何避免在每次调用我的 webhook 时破坏速率限制?我尝试了 OAuth 2,但 Podio 文档对我没有帮助。没有任何尝试对我有用。

您是否有任何方法将身份验证数据保存在内存/数据库中,以便能够将其用于来自多个 webhook 调用的每个 password 身份验证?

任何帮助将不胜感激!

解决方案

我在 Podio PHP API 类中发现了一些有趣的东西:

这就是我所做的:

// Set user API key
Podio::setup('user-key', 'wejt9wetwerith34rtfhwetu34hwerud);

// Init refresh_token variable (avoid PHP warning if any refresh_token found in database)
$refresh_token = null;

// Get refresh_token from database if exists
$refresh_token = REFRESH_TOKEN_FROM_DATABASE;

// Authenticate
try{
    // Authenticate with refresh token stored in database
    Podio::authenticate( 'refresh_token', array( 'refresh_token' => $refresh_token ) );
}

// Authentication failed, request new refresh_token
catch ( Exception $ex ) {
    Podio::authenticate_with_password( 'aaa', 'bbb' );
    
    // Get Oauth data including refresh token
    $oauth = Podio::$oauth;
    
    // Authenticate with refresh token
    Podio::authenticate( 'refresh_token', array( 'refresh_token' => $oauth->refresh_token ) );

   // Store $oauth->refresh_token in database for next webhook call...
}

非常重要在您的脚本中使用相同的用户 API 密钥以避免身份验证速率限制破坏,因为 refresh_token 链接到用于发出请求的用户 API 密钥。

【问题讨论】:

  • @hassanmaleki - 你的问题(你链接的那个)与这个问题有什么关系?评论应该是为了澄清一个问题,而不是宣传另一个问题。

标签: podio


【解决方案1】:

播音文档:

  1. 对于身份验证(一般): https://developers.podio.com/authentication
  2. 对于 php 认证:http://podio.github.io/podio-php/authentication/
  3. 对于 php 会话管理: http://podio.github.io/podio-php/sessions/

【讨论】:

  • 他写道,文档没有帮助。我相信一个 sn-p 或逻辑上下文会是一个更好的答案。
  • @VincentPoirier 是对的。我想要一个 sn-p 以查看我从 Podio 文档中没有理解的内容。上面的代码是避免身份验证速率限制破坏的真正方法吗?任何进一步的解释将不胜感激。
  • Do you have any way to keep in memory/database authentication data to be able to use it for each password authentication from multiple webhook call? - 是的,这称为会话管理,有关如何实现它的所有详细信息都在这里podio.github.io/podio-php/sessions
【解决方案2】:

答案在上面原始帖子的解决方案部分中描述。

【讨论】:

  • 您的解决方案可行,但仍不完美。无需每次拨打Podio::authenticate( 'refresh_token'。您应该保存 access_tokenrefresh_token 并使用它们来创建 PodioOAuth 对象。然后,如果您有很多电话,将有 0 个身份验证请求,并且偶尔会使用refresh_token 获取新的access_token
  • 能否请您举一个PodioOAuth在我的例子中的用法示例?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多