OAuthAuthenticator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 49
ccs 0
cts 20
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A authenticate() 0 19 1
A __construct() 0 6 1
1
<?php
2
3
namespace Kodus\Mail\SMTP\Authenticator;
4
5
use Kodus\Mail\SMTP\SMTPAuthenticator;
6
use Kodus\Mail\SMTP\SMTPClient;
7
8
/**
9
 * TODO finish this untested, partial implementation
10
 *
11
 * @see https://github.com/kodus/mail/issues/1
12
 *
13
 * @see https://tools.ietf.org/html/rfc7628
14
 */
15
class OAuthAuthenticator implements SMTPAuthenticator
16
{
17
    /**
18
     * @var string
19
     */
20
    private $user;
21
22
    /**
23
     * @var string
24
     */
25
    private $host;
26
27
    /**
28
     * @var string
29
     */
30
    private $port;
31
32
    /**
33
     * @var string
34
     */
35
    private $token;
36
37
    public function __construct(string $user, string $host, string $port, string $token)
38
    {
39
        $this->user = $user;
40
        $this->host = $host;
41
        $this->port = $port;
42
        $this->token = $token;
43
    }
44
45
    public function authenticate(SMTPClient $client): void
46
    {
47
        // NOTE: I don't know if any of this is correct or not - it was ported from somewhere else
48
49
        $auth_str = sprintf("n,a=%s,%shost=%s%sport=%s%sauth=Bearer %s%s%s",
50
            $this->user,
51
            chr(1),
52
            $this->host,
53
            chr(1),
54
            $this->port,
55
            chr(1),
56
            $this->token,
57
            chr(1),
58
            chr(1)
59
        );
60
61
        $auth_str = base64_encode($auth_str);
62
63
        $client->sendCommand("AUTH OAUTHBEARER {$auth_str}", "235");
64
    }
65
}
66