-
Notifications
You must be signed in to change notification settings - Fork 1
/
OAuth1.php
123 lines (101 loc) · 2.82 KB
/
OAuth1.php
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
/**
* @author Nino Škopac <nino@recgr.com>
* @copyright 2016 Nino Škopac
* @license whatever lol
* @version 0.1
* @summary OAuth1 signature generator, PHP7 style.
*/
declare(strict_types=1);
namespace Recgr;
class OAuth1 {
private $payload = [
'oauth_consumer_key' => null,
'oauth_nonce' => null,
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => null,
'oauth_version' => '1.0'
];
/**
* Gets OAUth payload
*/
public function getPayload() : array {
return $this->payload;
}
/**
* Sets consumer key
*/
public function setConsumerKey(string $consumerKey) : self {
$this->payload['oauth_consumer_key'] = $consumerKey;
return $this;
}
/**
* Sets oauth_token
*/
public function setOAuthToken(string $OAuthToken) : self {
$this->payload['oauth_token'] = $OAuthToken;
return $this;
}
/**
* Sets access_token
*/
public function setAccessToken(string $accessToken) : self {
return $this->setOAuthToken($accessToken);
}
/**
* Sets verifier token
*/
public function setVerifierToken(string $verifierToken) : self {
$this->payload['oauth_verifier'] = $verifierToken;
return $this;
}
/**
* Sets oauth_signature
*/
public function setSignature(string $signature) : self {
$this->payload['oauth_signature'] = $signature;
return $this;
}
/**
* Gets oauth_signature
*/
public function getSignature() : string {
return $this->payload['oauth_signature'] ?? '';
}
/**
* Sets oauth_callback
*/
public function setCallback(string $callbackUrl) : self {
$this->payload['oauth_callback'] = $callbackUrl;
return $this;
}
/**
* Sets oauth_signature_method
*/
public function setSignatureMethod(string $hashAlgo) : self {
$this->payload['oauth_signature_method'] = $hashAlgo;
return $this;
}
/**
* Set arbitrary payload param
*/
public function setArbitrary(string $fieldName, string $fieldValue) : self {
$this->payload[$fieldName] = $fieldValue;
return $this;
}
/**
* Unset arbitrary payload param
*/
public function unsetArbitrary(string $fieldName) : self {
unset($this->payload[$fieldName]);
return $this;
}
/**
* Updates oauth_timestamp and oauth_nonce.
*/
public function refreshPayload() : self {
$this->payload['oauth_nonce'] = bin2hex(random_bytes(32));
$this->payload['oauth_timestamp'] = time();
return $this;
}
}