Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oauth: select auth scheme (XOAUTH2 vs OAUTHBEARER) #9289

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"pear/auth_sasl": "~1.1.0",
"pear/crypt_gpg": "~1.6.3",
"pear/mail_mime": "~1.10.11",
"pear/net_sieve": "~1.4.5",
"pear/net_smtp": "~1.10.0",
"pear/net_sieve": "~1.4.7",
"pear/net_smtp": "~1.12.0",
"pear/pear-core-minimal": "~1.10.1",
"roundcube/plugin-installer": "~0.3.5",
"roundcube/rtf-html-php": "^2.1"
Expand Down
10 changes: 2 additions & 8 deletions program/include/rcmail_oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@ class rcmail_oauth

public const JWKS_CACHE_TTL = 30; // TTL for JWKS (in seconds)

// prepare the OAUTHBEARER which is now the official protocol (rfc 7628)
// but currently implement mostly the formal XOAUTH2
/** @var string */
protected $auth_type = 'XOAUTH2';
/** @var string XOAUTH2, OAUTHBEAER, OAUTH=choose the supported method */
protected $auth_type = 'OAUTH';

/** @var rcmail */
protected $rcmail;
Expand Down Expand Up @@ -1009,13 +1007,11 @@ public function storage_init($options)
}

if ($this->login_phase) {
// enforce OAUTHBEARER/XOAUTH2 authorization type
$options['auth_type'] = $this->auth_type;
} elseif (isset($_SESSION['oauth_token'])) {
if ($this->check_token_validity($_SESSION['oauth_token']) === self::TOKEN_REFRESHED) {
$options['password'] = $this->rcmail->decrypt($_SESSION['password']);
}
// enforce OAUTHBEARER/XOAUTH2 authorization type
$options['auth_type'] = $this->auth_type;
}

Expand Down Expand Up @@ -1043,7 +1039,6 @@ public function smtp_connect($options)
// check token validity
$this->check_token_validity($_SESSION['oauth_token']);

// enforce OAUTHBEARER/XOAUTH2 authorization type
$options['smtp_user'] = '%u';
$options['smtp_pass'] = '%p';
$options['smtp_auth_type'] = $this->auth_type;
Expand All @@ -1064,7 +1059,6 @@ public function managesieve_connect($options)
if (isset($_SESSION['oauth_token'])) {
// check token validity
$this->check_token_validity($_SESSION['oauth_token']);
// enforce OAUTHBEARER/XOAUTH2 authorization type
$options['auth_type'] = $this->auth_type;
}

Expand Down
7 changes: 6 additions & 1 deletion program/lib/Roundcube/rcube_imap_generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -931,14 +931,19 @@ public function connect($host, $user, $password, $options = [])
$result = null;

// check for supported auth methods
if (!$auth_method || $auth_method == 'CHECK') {
if (!$auth_method || $auth_method === 'CHECK' || $auth_method === 'OAUTH') {
if ($auth_caps = $this->getCapability('AUTH')) {
$auth_methods = $auth_caps;
}

// Use best (for security) supported authentication method
$all_methods = ['DIGEST-MD5', 'CRAM-MD5', 'CRAM_MD5', 'PLAIN', 'LOGIN'];

// special case of OAUTH, use the supported method
if ($auth_method === 'OAUTH') {
$all_methods = ['OAUTHBEARER', 'XOAUTH2'];
}

if (!empty($this->prefs['gssapi_cn'])) {
array_unshift($all_methods, 'GSSAPI');
}
Expand Down