Skip to content

Commit

Permalink
fix reauthentication upon outlook oauth2 token expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
d99kris committed Aug 25, 2024
1 parent fa93600 commit a1dbffa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/nmail.1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.\" DO NOT MODIFY THIS FILE! It was generated by help2man.
.TH NMAIL "1" "August 2024" "nmail 5.1.14" "User Commands"
.TH NMAIL "1" "August 2024" "nmail 5.1.15" "User Commands"
.SH NAME
nmail \- ncurses mail
.SH SYNOPSIS
Expand Down
14 changes: 9 additions & 5 deletions src/oauth2nmail
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,15 @@ def refresh(provider, client_id, client_secret, token_store):
# parse response
jsonRefrResponse = json.loads(refrResponse.text)

if (refrResponse.status_code == 400) and (jsonRefrResponse["error"] == "invalid_grant") and (jsonRefrResponse["error_description"] == "Token has been expired or revoked."):
sys.stderr.write("token expired " + str(refrResponse) + "\n")
sys.stderr.write(str(json.loads(refrResponse.text)) + "\n")
sys.stderr.write("attempt to reauthenticate\n")
return generate(provider, client_id, client_secret, token_store)
if (refrResponse.status_code == 400):
isInvalidGrant = (jsonRefrResponse["error"] == "invalid_grant")
isDescGmailExpired = (jsonRefrResponse["error_description"] == "Token has been expired or revoked.")
isDescOutlookExpired = ("The user could not be authenticated as the grant is expired. The user must sign in again." in jsonRefrResponse["error_description"])
if isInvalidGrant and (isDescGmailExpired or isDescOutlookExpired):
sys.stderr.write("token expired " + str(refrResponse) + "\n")
sys.stderr.write(str(json.loads(refrResponse.text)) + "\n")
sys.stderr.write("attempt to reauthenticate\n")
return generate(provider, client_id, client_secret, token_store)

if refrResponse.status_code != 200:
sys.stderr.write("token refresh failed " + str(refrResponse) + "\n")
Expand Down
2 changes: 1 addition & 1 deletion src/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "version.h"

#define NMAIL_VERSION "5.1.14"
#define NMAIL_VERSION "5.1.15"

std::string Version::GetBuildOs()
{
Expand Down

0 comments on commit a1dbffa

Please sign in to comment.