У меня есть ионно-угловое приложение nkvshopapp
с WordPress в качестве бэкэнда. Wordpress локально размещается с определенным плагином oauth1.0 и ключами oauth.
До вчерашнего утра, nkvshopapp
работал нормально, и он отображал все сообщения и категории с моего сайта WordPress. Он внезапно перестал работать и теперь отображает ошибку OAuth signature not defined
. Я дважды проверил ключи OAuth, и они были такими же, как и раньше (то есть не обновлялись заново). И в файле index.html, и в файле config.ts все те же, что и раньше. Мое приложение предназначено для загрузки дополнительного Javascript (nkvshopapp.js), поэтому я также проверил функцию OAuth в nkvshopapp.js (на случай, если кто-нибудь взломал мой компьютер и внес в него изменения ... становясь параноиком, я знаю:)
Наконец, я дважды проверил в Почтальоне, проверяются ли ключи Oauth; и почтальон не отображает никаких ошибок или предупреждений.
Я что-то упустил? Любые предложения или указатели будут очень полезны.
Пожалуйста, помогите.
Вот выдержки из index.html, config.ts и nkvshopapp.js.
.
/ index.html:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="UTF-8">
<title>NKVShop</title>
<meta name="viewport" content="viewport-fit=cover, width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<link rel="icon" type="image/x-icon" href="assets/icon/favicon.ico">
<link rel="manifest" href="manifest.json">
<meta name="theme-color" content="#4e8ef7">
<!-- add to homescreen for ios -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<!-- cordova.js required for cordova apps -->
<script src="cordova.js"></script>
<script src="nkvshopapp.js"></script>
</script>-->
.
/ приложение / WWW / nkvshopapp.js:
function OAuthSignature() {
}
OAuthSignature.prototype.generate = function (httpMethod, url, parameters, consumerSecret, tokenSecret, options) {
var signatureBaseString = new SignatureBaseString(httpMethod, url, parameters).generate();
var encodeSignature = true;
if (options) {
encodeSignature = options.encodeSignature;
}
return new HmacSha1Signature(signatureBaseString, consumerSecret, tokenSecret).generate(encodeSignature);
//return new signatureBaseString;
};
// Specification: http://oauth.net/core/1.0/#anchor14
// url: if the scheme is missing, http will be added automatically
function SignatureBaseString(httpMethod, url, parameters) {
//parameters = new ParametersLoader(parameters).get();
this._httpMethod = new HttpMethodElement(httpMethod).get();
this._url = new UrlElement(url).get();
this._parameters = parameters;
//this._parameters = new ParametersElement(parameters).get();
this._rfc3986 = new Rfc3986();
}
SignatureBaseString.prototype = {
generate : function () {
// HTTP_METHOD & url & parameters
return this._rfc3986.encode(this._httpMethod) + '&'
+ this._rfc3986.encode(this._url) + '&'
+ this._rfc3986.encode(this._parameters);
}
};
.
/ SRC / поставщиков / услуг / config.ts:
import { Injectable } from '@angular/core';
import { URLSearchParams } from '@angular/http';
import { Headers } from '@angular/http';
declare var oauthSignature: any;
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
@Injectable()
export class Config {
url: any = 'http://127.0.1.1:8080/wordpress';
consumerKey: any = 'Hl8XcAPgCqt6';
consumerSecret: any = '3xGMKgiXBP7HoI2i9dkf3HByepZRSmSjYGQNszvXwzfOO0YW';
oneSignalAppId: any = '';
googleProjectId: any = '';
language: any = 'english';
appDir: any = 'ltr';
appRateIosAppId: any = '12345678';
appRateAndroidLink: any = '';
appRateWindowsId: any = '12345678';
shareAppMessage: any = 'download it';
shareAppSubject: any = 'Hi';
shareAppURL: any = '';
shareAppChooserTitle: any = 'select app';
supportEmail: any = 'nkvshopapp@gmail.com';
oauth: any;
signedUrl: any;
randomString: any;
oauth_nonce: any;
oauth_signature_method: any;
encodedSignature: any;
searchParams: any;
customer_id: any;
params: any;
options: any = {};
constructor() {
this.options.withCredentials = true;
this.options.headers = headers;
this.oauth = oauthSignature;
this.oauth_signature_method = 'HMAC-SHA1';
this.searchParams = new URLSearchParams();
this.params = {};
this.params.oauth_consumer_key = this.consumerKey;
this.params.oauth_signature_method = 'HMAC-SHA1';
this.params.oauth_version = '1.0';
}
setOauthNonce(length, chars) {
var result = '';
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
return result;
}