Skip to content

Commit

Permalink
Move code for oauth tokens in standalone package swissup/module-oauth…
Browse files Browse the repository at this point in the history
…2-client
  • Loading branch information
0m3r committed Jul 11, 2024
1 parent d8b224d commit df19c6c
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 277 deletions.
8 changes: 4 additions & 4 deletions Api/Data/ServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ServiceInterface
const PORT = 'port';
const SECURE = 'secure';
const AUTH = 'auth';
const TOKEN = 'token';
const TOKEN_ID = 'token_id';
const KEY = 'key';
const REMOVE = 'remove';

Expand Down Expand Up @@ -120,7 +120,7 @@ public function getAuth();
/**
* @return mixed
*/
public function getToken();
public function getTokenId();

/**
* Get key
Expand Down Expand Up @@ -225,10 +225,10 @@ public function setSecure($secure);
public function setAuth($auth);

/**
* @param string $token
* @param int $tokenId
* @return \Swissup\Email\Api\Data\ServiceInterface
*/
public function setToken($token);
public function setTokenId($tokenId);

/**
* Set key
Expand Down
4 changes: 2 additions & 2 deletions Controller/Adminhtml/Email/Service/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public function execute()
$this->session->setFormData(false);

if ($model->hasData('callback_url')) {
$flowUrl = $model->getData('callback_url');
return $resultRedirect->setUrl($flowUrl);
$callbackUrl = $model->getData('callback_url');
return $resultRedirect->setUrl($callbackUrl);
}

if ($this->getRequest()->getParam('back')) {
Expand Down
155 changes: 0 additions & 155 deletions Controller/Gmail/GetOAuth2Token.php

This file was deleted.

4 changes: 2 additions & 2 deletions Mail/Transport/GmailOAuth2.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public function __construct(
SmtpOptions $options = null
) {
if (! $options instanceof SmtpOptions) {
$host = 'smtp.gmail.com';
$port = 587;
$host = isset($config['host']) ? $config['host'] : 'smtp.gmail.com';
$port = isset($config['port']) ? (int) $config['port'] : 587;

if (!isset($config['token']) || !isset($config['token']['access_token'])) {
$phrase = new \Magento\Framework\Phrase('token is broken');
Expand Down
10 changes: 5 additions & 5 deletions Model/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,11 @@ public function getAuth()
}

/**
* @return string
* @return int
*/
public function getToken()
public function getTokenId()
{
return $this->getData(self::TOKEN);
return $this->getData(self::TOKEN_ID);
}

/**
Expand Down Expand Up @@ -309,9 +309,9 @@ public function setAuth($auth)
return $this->setData(self::AUTH, $auth);
}

public function setToken($token)
public function setTokenId($tokenId)
{
return $this->setData(self::TOKEN, $token);
return $this->setData(self::TOKEN_ID, $tokenId);
}

/**
Expand Down
33 changes: 2 additions & 31 deletions Model/Service/Encryptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,20 @@ class Encryptor implements ServiceEncryptorInterface
*/
private $encryptor;

/**
* @var SerializerInterface
*/
private $serializer;

/**
* @param EncryptorInterface $encryptor
*/
public function __construct(EncryptorInterface $encryptor, SerializerInterface $serializer)
public function __construct(EncryptorInterface $encryptor)
{
$this->encryptor = $encryptor;
$this->serializer = $serializer;
}

/**
* @return string[]
*/
private function getAttributes()
{
return ['password', 'token'];
}

/**
* @return string[]
*/
private function getSerializableAttributes()
{
return ['token'];
}

/**
* @param $attribute
* @return bool
*/
private function isSerializableAttribute($attribute)
{
return in_array($attribute, $this->getSerializableAttributes());
return ['password'];
}

/**
Expand All @@ -60,9 +37,6 @@ public function encrypt(ServiceInterface $object): void
{
foreach ($this->getAttributes() as $attributeCode) {
$value = $object->getData($attributeCode);
if ($this->isSerializableAttribute($attributeCode)) {
$value = $this->serializer->serialize($value);
}
if ($value) {
$object->setData($attributeCode, $this->encryptor->encrypt($value));
}
Expand All @@ -80,9 +54,6 @@ public function decrypt(ServiceInterface $object): void
if ($value) {
try {
$value = $this->encryptor->decrypt($value);
if ($this->isSerializableAttribute($attributeCode)) {
$value = $this->serializer->unserialize($value);
}
$object->setData($attributeCode, $value);
} catch (\Exception $e) {
// value is not encrypted or something wrong with encrypted data
Expand Down
Loading

0 comments on commit df19c6c

Please sign in to comment.