-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaccesstokenrequest.cpp
39 lines (29 loc) · 1.35 KB
/
accesstokenrequest.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "accesstokenrequest.h"
/*
* Author: Zadock Maloba
* E-mail: zadockmaloba@outlook.com
* Twitter: zadock_254
* copyright: Zadock Maloba, 2022
*/
namespace DarajaCpp {
AccessTokenRequest::AccessTokenRequest(QString consumerKey, QString consumerSecret)
: m_consumerKey(consumerKey),
m_consumerSecret(consumerSecret),
m_authUrl("https://sandbox.safaricom.co.ke/oauth/v1/generate?grant_type=client_credentials")
{
auto const authHeader = QString(consumerKey+":"+consumerSecret).toUtf8().toBase64();
this->m_httpRequest.setUrl(this->m_authUrl);
this->m_httpRequest.setRawHeader("Content-Type", "application/json; charset=utf8");
this->m_httpRequest.setRawHeader("Authorization", QByteArray("Basic ").append(authHeader));
}
QNetworkRequest *AccessTokenRequest::renderRequest(NetworkHandler *netH)
{
netH->get(&m_httpRequest);
return &m_httpRequest;
}
const QString &AccessTokenRequest::consumerSecret() const {return m_consumerSecret;}
void AccessTokenRequest::setConsumerSecret(const QString &newConsumerSecret){ m_consumerSecret = newConsumerSecret; }
const QString &AccessTokenRequest::consumerKey() const{ return m_consumerKey; }
void AccessTokenRequest::setConsumerKey(const QString &newConsumerKey){ m_consumerKey = newConsumerKey; }
const QNetworkRequest &AccessTokenRequest::httpRequest() const{ return m_httpRequest; }
}