要获取OAuth令牌,我想使用自定义网址方案作为我的iOS应用的回调网址,例如myapp://oauth-callback
。
然而,似乎Magento无法处理这样的URL方案,因为它返回时出现以下错误消息
HTTP Status 400: Bad Request, Response: oauth_problem=parameter_rejected&message=oauth_callback
如果我设置一个以http://开头的回调网址,请求确实有效并且我返回了一个OAuth令牌,问题是操作系统会使用此网址打开浏览器,这是我们应用中不需要的行为。< / p>
答案 0 :(得分:0)
由于'myapp',您的网址在Zend_Uri :: check($ url)中无效。 这是check()函数:
public static function check($uri)
{
try {
$uri = self::factory($uri);
} catch (Exception $e) {
return false;
}
return $uri->valid();
}
让我们看看工厂是如何运作的:
public static function factory($uri = 'http', $className = null)
{
// Separate the scheme from the scheme-specific parts
$uri = explode(':', $uri, 2);
$scheme = strtolower($uri[0]);
$schemeSpecific = isset($uri[1]) === true ? $uri[1] : '';
if (strlen($scheme) === 0) {
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('An empty string was supplied for the scheme');
}
// Security check: $scheme is used to load a class file, so only alphanumerics are allowed.
if (ctype_alnum($scheme) === false) {
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception('Illegal scheme supplied, only alphanumeric characters are permitted');
}
if ($className === null) {
/**
* Create a new Zend_Uri object for the $uri. If a subclass of Zend_Uri exists for the
* scheme, return an instance of that class. Otherwise, a Zend_Uri_Exception is thrown.
*/
switch ($scheme) {
case 'http':
// Break intentionally omitted
case 'https':
$className = 'Zend_Uri_Http';
break;
case 'mailto':
// TODO
default:
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported");
break;
}
}
#require_once 'Zend/Loader.php';
try {
Zend_Loader::loadClass($className);
} catch (Exception $e) {
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("\"$className\" not found");
}
$schemeHandler = new $className($scheme, $schemeSpecific);
if (! $schemeHandler instanceof Zend_Uri) {
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("\"$className\" is not an instance of Zend_Uri");
}
return $schemeHandler;
}
它为http://和https:// schemes使用Zend_Uri_Http类。您只需要在列表中添加自己的方案。
如何解决?
switch ($scheme) {
case 'http':
// Break intentionally omitted
case 'https':
$className = 'Zend_Uri_Http';
break;
case 'myapp':
$className = 'Zend_Uri_Http';
break;
case 'mailto':
// TODO
default:
#require_once 'Zend/Uri/Exception.php';
throw new Zend_Uri_Exception("Scheme \"$scheme\" is not supported");
break;
}