Skip to content

Commit

Permalink
Microsoft Exchange oAuth for SMTP - closes #4072
Browse files Browse the repository at this point in the history
  • Loading branch information
freescout-help-desk committed Jun 13, 2024
1 parent 7e8e514 commit 8510ee8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Misc/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static function setMailDriver($mailbox = null, $user_from = null, $conver
$oauth = $mailbox->oauthEnabled();

// Refresh Access Token.
if ($oauth) {
if ($oauth && !strstr($mailbox->out_username, '@')) {
if ((strtotime($mailbox->oauthGetParam('issued_on')) + (int)$mailbox->oauthGetParam('expires_in')) < time()) {
// Try to get an access token (using the authorization code grant)
$token_data = \MailHelper::oauthGetAccessToken(\MailHelper::OAUTH_PROVIDER_MICROSOFT, [
Expand Down Expand Up @@ -134,7 +134,7 @@ public static function setMailDriver($mailbox = null, $user_from = null, $conver
if ($mailbox->out_method == Mailbox::OUT_METHOD_SMTP) {
\Config::set('mail.host', $mailbox->out_server);
\Config::set('mail.port', $mailbox->out_port);
if ($oauth) {
if ($oauth && !strstr($mailbox->out_username, '@')) {
\Config::set('mail.auth_mode', 'XOAUTH2');
\Config::set('mail.username', $mailbox->email);
\Config::set('mail.password', $mailbox->oauthGetParam('a_token'));
Expand Down
4 changes: 2 additions & 2 deletions resources/views/mailboxes/connection.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<label for="out_username" class="col-sm-2 control-label">{{ __('Username') }}</label>

<div class="col-sm-6">
<input id="out_username" type="text" class="form-control input-sized @if ($mailbox->oauthEnabled()) disabled @endif" name="out_username" value="{{ old('out_username', $mailbox->out_username) }}" maxlength="100" @if ($mailbox->out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled()) readonly @endif>
<input id="out_username" type="text" class="form-control input-sized @if ($mailbox->oauthEnabled() && strstr($mailbox->out_username, '@')) disabled @endif" name="out_username" value="{{ old('out_username', $mailbox->out_username) }}" maxlength="100" @if ($mailbox->out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled() && strstr($mailbox->out_username, '@')) readonly @endif>

@include('partials/field_error', ['field'=>'out_username'])
</div>
Expand All @@ -97,7 +97,7 @@
<label for="out_password" class="col-sm-2 control-label">{{ __('Password') }}</label>

<div class="col-sm-6">
<input id="out_password" type="password" class="form-control input-sized @if ($mailbox->oauthEnabled()) disabled @endif" name="out_password" value="{{ old('out_password', $mailbox->outPasswordSafe()) }}" maxlength="255" @if ($mailbox->out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled()) readonly @endif>
<input id="out_password" type="password" class="form-control input-sized @if ($mailbox->oauthEnabled() && strstr($mailbox->out_username, '@')) disabled @endif" name="out_password" value="{{ old('out_password', $mailbox->outPasswordSafe()) }}" maxlength="255" @if ($mailbox->out_method == App\Mailbox::OUT_METHOD_SMTP) @endif autofocus {{-- This added to prevent autocomplete in Chrome --}}autocomplete="new-password" @if ($mailbox->oauthEnabled() && strstr($mailbox->out_username, '@')) readonly @endif>

<p class="form-help">
<small @if ($mailbox->oauthGetParam('provider') == \MailHelper::OAUTH_PROVIDER_MICROSOFT) class="text-success" @endif>Microsoft Exchange</small>
Expand Down

0 comments on commit 8510ee8

Please sign in to comment.