0

AngularJS でフロントエンド アプリケーションを開発しています。elgg プラットフォームにログインしようとしています。HMAC 認証を使用する場合は、こちらのドキュメントで説明されているように、いくつかのカスタム ヘッダーを追加する必要があります。AngularJS では、インターセプターを使用しました。

$httpProvider.interceptors.push(function($q, HMAC){
    return {
        // optional method
        'request': function(config) {
            // do something on success
            console.log("Interceptor Config-> ",config);
            console.log("HTTP? --> ",config.url.indexOf('http'));

            if(config.url.indexOf('http') == 0){
                //do something only on http requests
                config.headers = config.headers || {};

                config.headers['X-Elgg-apikey'] = "";
                config.headers['X-Elgg-time'] = "";
                config.headers['X-Elgg-none'] = "";
                config.headers['X-Elgg-hmac'] = "";
                config.headers['X-Elgg-hmac-algo'] = "";

            }

            console.log("Return -->", config);
            return config || $q.when(config);
        }
    };
});

しかし、私が得た応答は次のとおりです。

XMLHttpRequest cannot load http://localhost/elgg-1.9.8/elgg-1.9.8/services/api/rest/xml/?method=auth.gettoken. Request header field X- Elgg-hmac-algo is not allowed by Access-Control-Allow-Headers.

localhost の Web サーバーに Apache があり、次のように構成しました。
<Directory /> Header always set Access-Control-Allow-Origin "*" Header always set Access-Control-Request-Headers "*" Header always set Access-Control-Request-Method "*" AllowOverride none Require all denied </Directory>

また、応答ヘッダーとこれを確認しました: HTTP/1.1 200 OK Date: Sat, 30 May 2015 13:37:07 GMT Server: Apache/2.4.10 (Unix) OpenSSL/1.0.1j PHP/5.6.3 mod_perl/2.0.8-dev Perl/v5.16.3 Access-Control-Allow-Origin: * Access-Control-Request-Headers: * Access-Control-Request-Method: * X-Powered-By: PHP/5.6.3 Cache-Control: no-cache, must-revalidate Expires: Fri, 05 Feb 1982 00:00:00 -0500 Vary: Accept-Encoding,User-Agent Content-Encoding: gzip Content-Length: 81 Keep-Alive: timeout=5, max=100 Connection: Keep-Alive Content-Type: text/html; charset=UTF-8

バグがどこにあるのかわかりません。サーバーでヘッダー応答を設定しましたが、コンソールでまだこのエラーが発生します。ありがとう

4

0 に答える 0