0

我想在我的 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
4

1 回答 1

1

我通过以下方式解决了这个问题:

1:导入 Crypto-js 包

2:创建签名

3:秒创建时间戳

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)
    );
  }
}
于 2018-05-24T12:29:30.257 回答