Skip to content

Commit

Permalink
reworked all comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kc committed Dec 12, 2023
1 parent dd59fe8 commit 4bcf536
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
22 changes: 7 additions & 15 deletions program/include/rcmail_oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public function __construct($options = [])
'verify_peer' => $this->rcmail->config->get('oauth_verify_peer', true),
'auth_parameters' => $this->rcmail->config->get('oauth_auth_parameters', []),
'login_redirect' => $this->rcmail->config->get('oauth_login_redirect', false),
'smtp_auth_type' => $this->rcmail->config->get('smtp_auth_type'),
];
}

Expand Down Expand Up @@ -215,7 +214,7 @@ public function request_access_token($auth_code, $state = null)
$oauth_client_id = $this->options['client_id'];
$oauth_client_secret = $this->options['client_secret'];
$oauth_identity_uri = $this->options['identity_uri'];
$oauth_provider = $this->options['provider'];
$oauth_provider = $this->options['provider'];

if (!empty($oauth_token_uri) && !empty($oauth_client_secret)) {
try {
Expand All @@ -240,20 +239,15 @@ public function request_access_token($auth_code, $state = null)
],
]);

// Test if body is already Json
json_decode( $response->getBody() );
if ( json_last_error() === 0 )
$data = json_decode($response->getBody(), true);
else
$data = \GuzzleHttp\json_decode($response->getBody(), true);
$data = json_decode($response->getBody(), true);

// auth success
if (!empty($data['access_token'])) {
$username = null;
$identity = null;

// for Kinde we need to transform "bearer" into "Bearer"
if ( strpos( strtolower ( $oauth_provider ),"kinde") !== false )
if ( stripos( strtolower ( $oauth_provider ),"kinde") !== false )
$authorization = sprintf('%s %s', ucfirst( $data['token_type']), $data['access_token']);
else
$authorization = sprintf('%s %s', $data['token_type'], $data['access_token']);
Expand Down Expand Up @@ -507,17 +501,15 @@ public function storage_init($options)
*/
public function smtp_connect($options)
{
$smtp_user = $this->options['smtp_user'];
$smtp_pass = $this->options['smtp_pass'];
$smtp_user = $this->options['smtp_user'];
$smtp_pass = $this->options['smtp_pass'];

if (isset($_SESSION['oauth_token'])) {

// check token validity
$this->check_token_validity($_SESSION['oauth_token']);

// enforce XOAUTH2 authorization type if not explicitly set to none KVV
if ( ( $smtp_user != '' ) || ( $smtp_pass != '' ) ) {

// skip XOAUTH2 authorization, if indicated
if (($smtp_user != '')||($smtp_pass != '')) {
$options['smtp_user'] = '%u';
$options['smtp_pass'] = '%p';
$options['smtp_auth_type'] = 'XOAUTH2';
Expand Down
7 changes: 1 addition & 6 deletions program/lib/Roundcube/rcube_smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,7 @@ public function connect($host = null, $port = null, $user = null, $pass = null)
}

// attempt to authenticate to the SMTP server
if ((($smtp_user && $smtp_pass) ||
($smtp_auth_type == 'GSSAPI')
) &&
// but skip if instructed to
( ( $CONFIG['smtp_user'] != '' ) || ( $CONFIG['smtp_pass'] != '' ) )
) {
if (($smtp_user && $smtp_pass) || ($smtp_auth_type == 'GSSAPI')) {
// IDNA Support
if (strpos($smtp_user, '@')) {
$smtp_user = rcube_utils::idn_to_ascii($smtp_user);
Expand Down

0 comments on commit 4bcf536

Please sign in to comment.