minor: throw exception if refresh_token is not present
This commit is contained in:
parent
06c5a7226d
commit
064ffef8b9
3 changed files with 12 additions and 5 deletions
|
|
@ -32,14 +32,21 @@ class Oauth:
|
|||
self._access_token = access_token
|
||||
self._refresh_token = refresh_token
|
||||
|
||||
self.validate_implementation()
|
||||
self.validate()
|
||||
|
||||
def validate_implementation(self) -> None:
|
||||
def validate(self) -> None:
|
||||
if self.service != "GMail":
|
||||
raise NotImplementedError(
|
||||
f"Service {self.service} currently doesn't have oauth implementation."
|
||||
)
|
||||
|
||||
if not self._refresh_token:
|
||||
frappe.throw(
|
||||
frappe._("Please Authorize OAuth."),
|
||||
OAuthenticationError,
|
||||
frappe._("OAuth Error"),
|
||||
)
|
||||
|
||||
@property
|
||||
def _auth_string(self) -> str:
|
||||
return "user=%s\1auth=Bearer %s\1\1" % (self.email, self._access_token)
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ class EmailServer:
|
|||
self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout")
|
||||
)
|
||||
|
||||
if self.settings.use_oauth and self.settings.refresh_token:
|
||||
if self.settings.use_oauth:
|
||||
Oauth(
|
||||
self.imap,
|
||||
self.settings.email_account,
|
||||
|
|
@ -133,7 +133,7 @@ class EmailServer:
|
|||
self.settings.host, self.settings.incoming_port, timeout=frappe.conf.get("pop_timeout")
|
||||
)
|
||||
|
||||
if self.settings.use_oauth and self.settings.refresh_token:
|
||||
if self.settings.use_oauth:
|
||||
Oauth(
|
||||
self.pop,
|
||||
self.settings.email_account,
|
||||
|
|
|
|||
|
|
@ -111,7 +111,7 @@ class SMTPServer:
|
|||
|
||||
self.secure_session(_session)
|
||||
|
||||
if self.use_oauth and self.refresh_token:
|
||||
if self.use_oauth:
|
||||
Oauth(
|
||||
_session, self.email_account, self.login, self.access_token, self.refresh_token, self.service
|
||||
).connect()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue