mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Update column for refresh tokens
This commit is contained in:
parent
d9ca212f81
commit
213a51ad62
@ -163,7 +163,7 @@ class CompanySettings extends BaseSettings
|
|||||||
public $require_quote_signature = false; //@TODO ben to confirm
|
public $require_quote_signature = false; //@TODO ben to confirm
|
||||||
|
|
||||||
//email settings
|
//email settings
|
||||||
public $email_sending_method = 'default'; //enum 'default','gmail' //@implemented
|
public $email_sending_method = 'default'; //enum 'default','gmail','office365' //@implemented
|
||||||
public $gmail_sending_user_id = '0'; //@implemented
|
public $gmail_sending_user_id = '0'; //@implemented
|
||||||
|
|
||||||
public $reply_to_email = ''; //@implemented
|
public $reply_to_email = ''; //@implemented
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
namespace App\Helpers\Mail;
|
namespace App\Helpers\Mail;
|
||||||
|
|
||||||
use Illuminate\Mail\Transport\Transport;
|
use Illuminate\Mail\Transport\Transport;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
use Swift_Mime_SimpleMessage;
|
use Swift_Mime_SimpleMessage;
|
||||||
use Microsoft\Graph\Graph;
|
use Microsoft\Graph\Graph;
|
||||||
use Microsoft\Graph\Model\UploadSession;
|
use Microsoft\Graph\Model\UploadSession;
|
||||||
@ -29,8 +30,9 @@ class Office365MailTransport extends Transport
|
|||||||
$this->beforeSendPerformed($message);
|
$this->beforeSendPerformed($message);
|
||||||
|
|
||||||
$graph = new Graph();
|
$graph = new Graph();
|
||||||
|
$token = $message->getHeaders()->get('GmailToken')->getValue();
|
||||||
|
|
||||||
$graph->setAccessToken($this->getAccessToken());
|
$graph->setAccessToken($token);
|
||||||
|
|
||||||
// Special treatment if the message has too large attachments
|
// Special treatment if the message has too large attachments
|
||||||
$messageBody = $this->getBody($message, true);
|
$messageBody = $this->getBody($message, true);
|
||||||
@ -163,7 +165,7 @@ class Office365MailTransport extends Transport
|
|||||||
//add attachments if any
|
//add attachments if any
|
||||||
$attachments = [];
|
$attachments = [];
|
||||||
foreach ($message->getChildren() as $attachment) {
|
foreach ($message->getChildren() as $attachment) {
|
||||||
if ($attachment instanceof \Swift_Mime_SimpleMimeEntity) {
|
if ($attachment instanceof \Swift_Mime_SimpleMimeEntity && $attachment->getContentType() != 'text/plain') {
|
||||||
$attachments[] = [
|
$attachments[] = [
|
||||||
"@odata.type" => "#microsoft.graph.fileAttachment",
|
"@odata.type" => "#microsoft.graph.fileAttachment",
|
||||||
"name" => $attachment->getHeaders()->get('Content-Type')->getParameter('name'),
|
"name" => $attachment->getHeaders()->get('Content-Type')->getParameter('name'),
|
||||||
@ -285,23 +287,4 @@ class Office365MailTransport extends Transport
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getAccessToken()
|
|
||||||
{
|
|
||||||
$guzzle = new \GuzzleHttp\Client();
|
|
||||||
$url = 'https://login.microsoftonline.com/' . config('ninja.o365.tenant_id') . '/oauth2/v2.0/token';
|
|
||||||
$token = json_decode($guzzle->post($url, [
|
|
||||||
'form_params' => [
|
|
||||||
'client_id' => config('ninja.o365.client_id'),
|
|
||||||
'client_secret' => config('ninja.o365.client_secret'),
|
|
||||||
'scope' => 'https://graph.microsoft.com/.default',
|
|
||||||
'grant_type' => 'client_credentials',
|
|
||||||
],
|
|
||||||
])->getBody()->getContents());
|
|
||||||
|
|
||||||
nlog($token);
|
|
||||||
|
|
||||||
nlog($token->access_token);
|
|
||||||
|
|
||||||
return $token->access_token;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -184,12 +184,33 @@ class NinjaMailerJob implements ShouldQueue
|
|||||||
$this->mailer = 'gmail';
|
$this->mailer = 'gmail';
|
||||||
$this->setGmailMailer();
|
$this->setGmailMailer();
|
||||||
break;
|
break;
|
||||||
|
case 'office365':
|
||||||
|
$this->mailer = 'office365';
|
||||||
|
$this->setOfficeMailer();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function setOfficeMailer()
|
||||||
|
{
|
||||||
|
$sending_user = $this->nmo->settings->gmail_sending_user_id;
|
||||||
|
|
||||||
|
$user = User::find($this->decodePrimaryKey($sending_user));
|
||||||
|
$token = $user->oauth_user_token->access_token;
|
||||||
|
|
||||||
|
nlog("Sending via {$user->name()}");
|
||||||
|
|
||||||
|
$this->nmo
|
||||||
|
->mailable
|
||||||
|
->from($user->email, $user->name())
|
||||||
|
->withSwiftMessage(function ($message) use($token) {
|
||||||
|
$message->getHeaders()->addTextHeader('GmailToken', $token);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private function setGmailMailer()
|
private function setGmailMailer()
|
||||||
{
|
{
|
||||||
if(LaravelGmail::check())
|
if(LaravelGmail::check())
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class ChangeRefreshTokenColumnSize extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->text('oauth_user_refresh_token')->change();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user