我想在Magento的Angular应用中进行身份验证。我在StackOverflow中没有看到任何文档或问题,这有助于我弄清楚它!
const consumerKey = 'c05028de10c242378cf5fd7eb7dd1008';
const consumerSecret = '4350c23b9fda5f491ac5276218b3541d';
const baseUrl = 'http://someSite.localhost';
oauth = new HttpParams()
.set('callback', 'http://127.0.0.1:4200/login')
.set('consumer_key', consumerKey)
.set('consumer_secret', consumerSecret);
url = baseUrl + '/oauth/initiate';
initiate() {
return this.httpClient.post(this.url, this.oauth).subscribe(
data => console.log(data)
);
}
回复:
oauth_problem=parameter_absent&oauth_parameters_absent=oauth_consumer_key
答案 0 :(得分:1)
1:导入Crypto-js包
2:创建签名
3:在第二次创建TimeStamp
4:为Nonce创建随机数
5:Rest参数具有静态值
6:使用URL
中的所有这些参数发出请求import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse, HttpErrorResponse, HttpParams, HttpHeaders } from '@angular/common/http';
import { catchError, tap } from 'rxjs/operators';
import { throwError, Observable, of } from 'rxjs';
import * as CryptoJS from 'crypto-js';
@Injectable({
providedIn: 'root'
})
//Making Huge request Parameters
export class AuthService {
consumerKey = 'c05028de10c242378cf5fd7eb7dd1008';
consumerSecret = '4350c23b9fda5f491ac5276218b3541d';
baseUrl = 'http://someSite.localhost';
callback = 'http://127.0.0.1:4200/login/';
signature_method = 'HMAC-SHA1';
timestamp = Math.floor(Date.now() / 1000); // Timestamp in Second
signature = CryptoJS.HmacSHA1('Lazurd', this.consumerKey);
nonce = Math.random();
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'multipart/form-data',
})
};
// tslint:disable-next-line:max-line-length
url = this.baseUrl + '/oauth/initiate?oauth_consumer_key=' + this.consumerKey
+ '&oauth_callback=' + this.callback
+ '&oauth_consumer_secret=' + this.consumerSecret
+ '&oauth_signature_method=' + this.signature_method
+ '&oauth_nonce=' + this.nonce
+ '&oauth_timestamp=' + this.timestamp
+ '&oauth_signature=' + this.signature;
constructor(private httpClient: HttpClient) { }
// Get Magento Token
initiate() {
return this.httpClient.post(this.url, '', this.httpOptions).subscribe(
data => console.log(data)
);
}
}