SoundCloud API:重定向 url
SoundCloud API: redirect url
考虑这个来自 PHP 在 https://developers.soundcloud.com/docs/api/guide#authentication 的身份验证示例似乎建议您在让用户通过身份验证过程时将重定向 url 作为参数传递:
require_once 'Services/Soundcloud.php';
// create client object with app credentials
$client = new Services_Soundcloud(
'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URL');
// redirect user to authorize URL
header("Location: " . $client->getAuthorizeUrl());
注意构造函数调用中的 'REDIRECT_URL' 参数。
这似乎表明我可以将任意重定向 url 作为参数传递,就像您对 Twitter 所做的一样(API 非常相似)。
但是,如果我传递的 url 与为应用程序配置的唯一重定向 url 不匹配,当用户重定向到我的 url 时,我会收到错误消息:
error=redirect_uri_mismatch&error_description=+redirection+URI+provided+does+not+match+a+pre-registered+value.
那么,如果唯一有效值是为应用程序配置的重定向 url,那么该参数应该用于什么?
并且 如果用户在身份验证后只能被重定向到一个固定的 url,您应该如何处理身份验证??这使得 API 完全无法使用。当您让用户登录任何 API(例如 Twitter 或 Facebook)时,您需要他们 返回到他们单击 link 登录的页面,url 是唯一的限制是荒谬的。我见过的其他社交网络 api 没有此限制。
SoundCloud API 真的有缺陷还是我遗漏了什么?
我从 php-soundcloud 库(围绕这个可怕的 API 的一个相当不错的包装器)的作者 Glen Scott 那里得到了答案,他提供了一个解决方法。这很痛苦,因为它涉及到额外的重定向,但这是 API 允许的所有内容。
https://github.com/mptre/php-soundcloud/issues/36
我引用:
The API does not allow an arbitrary URL. As you noted, this is unlike
most other oAuth-backed social network API's. The workaround I can
recommend is using the state parameter to pass back your return URL.
You can do this when generating the authorization URL like this:
$client->getAuthorizeUrl(
array(
'state' => 'http://example.com/return'
) You'll get the state parameter added to the static redirect URL. For example, if you set your redirect URL to
http://example.com/callback then SoundCloud will redirect an
authenticated user to
http://example.com/callback?state=http://example.com/return
Your callback script will need to look for the state GET parameter,
and redirect using it.
考虑这个来自 PHP 在 https://developers.soundcloud.com/docs/api/guide#authentication 的身份验证示例似乎建议您在让用户通过身份验证过程时将重定向 url 作为参数传递:
require_once 'Services/Soundcloud.php';
// create client object with app credentials
$client = new Services_Soundcloud(
'CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URL');
// redirect user to authorize URL
header("Location: " . $client->getAuthorizeUrl());
注意构造函数调用中的 'REDIRECT_URL' 参数。
这似乎表明我可以将任意重定向 url 作为参数传递,就像您对 Twitter 所做的一样(API 非常相似)。
但是,如果我传递的 url 与为应用程序配置的唯一重定向 url 不匹配,当用户重定向到我的 url 时,我会收到错误消息: error=redirect_uri_mismatch&error_description=+redirection+URI+provided+does+not+match+a+pre-registered+value.
那么,如果唯一有效值是为应用程序配置的重定向 url,那么该参数应该用于什么?
并且 如果用户在身份验证后只能被重定向到一个固定的 url,您应该如何处理身份验证??这使得 API 完全无法使用。当您让用户登录任何 API(例如 Twitter 或 Facebook)时,您需要他们 返回到他们单击 link 登录的页面,url 是唯一的限制是荒谬的。我见过的其他社交网络 api 没有此限制。
SoundCloud API 真的有缺陷还是我遗漏了什么?
我从 php-soundcloud 库(围绕这个可怕的 API 的一个相当不错的包装器)的作者 Glen Scott 那里得到了答案,他提供了一个解决方法。这很痛苦,因为它涉及到额外的重定向,但这是 API 允许的所有内容。
https://github.com/mptre/php-soundcloud/issues/36
我引用:
The API does not allow an arbitrary URL. As you noted, this is unlike most other oAuth-backed social network API's. The workaround I can recommend is using the state parameter to pass back your return URL. You can do this when generating the authorization URL like this:
$client->getAuthorizeUrl( array( 'state' => 'http://example.com/return' ) You'll get the state parameter added to the static redirect URL. For example, if you set your redirect URL to
http://example.com/callback then SoundCloud will redirect an authenticated user to http://example.com/callback?state=http://example.com/return
Your callback script will need to look for the state GET parameter, and redirect using it.