gpt4 book ai didi

ios - Magento OAuth 身份验证无法处理自定义 URL 方案

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:00:10 24 4
gpt4 key购买 nike

为了取回 OAuth token ,我想使用自定义 URL 方案作为我的 iOS 应用程序的回调 URL,例如myapp://oauth-callback

但是 Magento 似乎无法处理这样的 URL 方案,因为它会返回以下错误消息

HTTP Status 400: Bad Request, Response: oauth_problem=parameter_rejected&message=oauth_callback

如果我设置一个以 http://开头的回调 URL,请求确实有效并且我得到了一个 OAuth token ,问题是操作系统使用这个 URL 打开浏览器,这是我们应用程序中不需要的行为。

最佳答案

你的 url 在 Zend_Uri::check($url) 中无效,因为 'myapp'。这是 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://方案使用 Zend_Uri_Http 类。您只需要在列表中添加自己的方案即可。

如何修复?

  1. 复制 lib/Zend/Uri.php 文件到 app/code/local/Zend/Uri.php
  2. 在工厂函数中找到“switch”代码块(~第 119 行)并将其替换为下一个:
    开关($方案){
    案例'http':
    //break 故意省略
    案例“https”:
    $className = 'Zend_Uri_Http';
    休息;
    案例“我的应用程序”:
    $className = 'Zend_Uri_Http';
    休息;
    案例'mailto':
    //去做
    默认:
    #require_once 'Zend/Uri/Exception.php';
    throw new Zend_Uri_Exception("不支持方案\"$scheme\"");
    休息;
    }
  3. 保存文件并清除 Magento 缓存。现在你的 myapp://方案将作为 http://和 https://

关于ios - Magento OAuth 身份验证无法处理自定义 URL 方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32067812/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com