Replace OAUTH2 with OAuth2 in the UI when it's not protocol codes.
This commit is contained in:
parent
b56c85f8f8
commit
e21b579711
50
src/oauth2.c
50
src/oauth2.c
|
@ -235,13 +235,13 @@ int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const
|
||||||
token = oauth2_get_token_from_response(provider, authcode);
|
token = oauth2_get_token_from_response(provider, authcode);
|
||||||
debug_print("Auth token: %s\n", token);
|
debug_print("Auth token: %s\n", token);
|
||||||
if (token == NULL) {
|
if (token == NULL) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 missing authentication code\n");
|
log_message(LOG_PROTOCOL, "OAuth2 missing authentication code\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
sock = sock_connect(OAUTH2info[i][OA2_BASE_URL], 443);
|
sock = sock_connect(OAUTH2info[i][OA2_BASE_URL], 443);
|
||||||
if (sock == NULL) {
|
if (sock == NULL) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 connecion error\n");
|
log_message(LOG_PROTOCOL, "OAuth2 connecion error\n");
|
||||||
g_free(token);
|
g_free(token);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const
|
||||||
sock_set_io_timeout(10);
|
sock_set_io_timeout(10);
|
||||||
sock->gnutls_priority = "NORMAL:!VERS-SSL3.0:!VERS-TLS1.0:!VERS-TLS1.1";
|
sock->gnutls_priority = "NORMAL:!VERS-SSL3.0:!VERS-TLS1.0:!VERS-TLS1.1";
|
||||||
if (ssl_init_socket(sock) == FALSE) {
|
if (ssl_init_socket(sock) == FALSE) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 SSL connecion error\n");
|
log_message(LOG_PROTOCOL, "OAuth2 SSL connecion error\n");
|
||||||
g_free(token);
|
g_free(token);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -308,18 +308,18 @@ int oauth2_obtain_tokens (Oauth2Service provider, OAUTH2Data *OAUTH2Data, const
|
||||||
OAUTH2Data->expiry = expiry;
|
OAUTH2Data->expiry = expiry;
|
||||||
OAUTH2Data->expiry_str = g_strdup_printf ("%i", expiry);
|
OAUTH2Data->expiry_str = g_strdup_printf ("%i", expiry);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token obtained\n");
|
||||||
}else{
|
}else{
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token not obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token not obtained\n");
|
||||||
debug_print("OAUTH2 - request: %s\n Response: %s", request, response);
|
debug_print("OAuth2 - request: %s\n Response: %s", request, response);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(oauth2_filter_refresh (response, refresh_token) == 0){
|
if(oauth2_filter_refresh (response, refresh_token) == 0){
|
||||||
OAUTH2Data->refresh_token = refresh_token;
|
OAUTH2Data->refresh_token = refresh_token;
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 refresh token obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 refresh token obtained\n");
|
||||||
}else{
|
}else{
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 refresh token not obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 refresh token not obtained\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
sock_close(sock, TRUE);
|
sock_close(sock, TRUE);
|
||||||
|
@ -356,7 +356,7 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
|
||||||
|
|
||||||
sock = sock_connect(OAUTH2info[i][OA2_BASE_URL], 443);
|
sock = sock_connect(OAUTH2info[i][OA2_BASE_URL], 443);
|
||||||
if (sock == NULL) {
|
if (sock == NULL) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 connecion error\n");
|
log_message(LOG_PROTOCOL, "OAuth2 connecion error\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
sock->ssl_cert_auto_accept = TRUE;
|
sock->ssl_cert_auto_accept = TRUE;
|
||||||
|
@ -364,7 +364,7 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
|
||||||
sock_set_io_timeout(10);
|
sock_set_io_timeout(10);
|
||||||
sock->gnutls_priority = "NORMAL:!VERS-SSL3.0:!VERS-TLS1.0:!VERS-TLS1.1";
|
sock->gnutls_priority = "NORMAL:!VERS-SSL3.0:!VERS-TLS1.0:!VERS-TLS1.1";
|
||||||
if (ssl_init_socket(sock) == FALSE) {
|
if (ssl_init_socket(sock) == FALSE) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 SSL connecion error\n");
|
log_message(LOG_PROTOCOL, "OAuth2 SSL connecion error\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,15 +415,15 @@ gint oauth2_use_refresh_token (Oauth2Service provider, OAUTH2Data *OAUTH2Data)
|
||||||
OAUTH2Data->expiry = expiry;
|
OAUTH2Data->expiry = expiry;
|
||||||
OAUTH2Data->expiry_str = g_strdup_printf ("%i", expiry);
|
OAUTH2Data->expiry_str = g_strdup_printf ("%i", expiry);
|
||||||
ret = 0;
|
ret = 0;
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token obtained\n");
|
||||||
}else{
|
}else{
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token not obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token not obtained\n");
|
||||||
debug_print("OAUTH2 - request: %s\n Response: %s", request, response);
|
debug_print("OAuth2 - request: %s\n Response: %s", request, response);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
debug_print("OAUTH2 - access token: %s\n", access_token);
|
debug_print("OAuth2 - access token: %s\n", access_token);
|
||||||
debug_print("OAUTH2 - access token expiry: %i\n", expiry);
|
debug_print("OAuth2 - access token expiry: %i\n", expiry);
|
||||||
|
|
||||||
sock_close(sock, TRUE);
|
sock_close(sock, TRUE);
|
||||||
g_free(body);
|
g_free(body);
|
||||||
|
@ -449,7 +449,7 @@ static gint oauth2_contact_server (SockInfo *sock, gchar *request, gchar *respon
|
||||||
startplus += 10;
|
startplus += 10;
|
||||||
|
|
||||||
if (sock_write (sock, request, len+1) < 0) {
|
if (sock_write (sock, request, len+1) < 0) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 socket write error\n");
|
log_message(LOG_PROTOCOL, "OAuth2 socket write error\n");
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,7 +469,7 @@ static gint oauth2_contact_server (SockInfo *sock, gchar *request, gchar *respon
|
||||||
} while ((toread > 0) && (time(NULL) < startplus));
|
} while ((toread > 0) && (time(NULL) < startplus));
|
||||||
|
|
||||||
if(time(NULL) >= startplus)
|
if(time(NULL) >= startplus)
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 socket timeout error \n");
|
log_message(LOG_PROTOCOL, "OAuth2 socket timeout error \n");
|
||||||
|
|
||||||
g_free(token);
|
g_free(token);
|
||||||
|
|
||||||
|
@ -527,17 +527,17 @@ gint oauth2_check_passwds (PrefsAccount *ac_prefs)
|
||||||
expiry = atoi(passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY));
|
expiry = atoi(passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY));
|
||||||
if (expiry > (g_get_real_time () / G_USEC_PER_SEC)){
|
if (expiry > (g_get_real_time () / G_USEC_PER_SEC)){
|
||||||
g_free(OAUTH2Data);
|
g_free(OAUTH2Data);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token still fresh\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token still fresh\n");
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_REFRESH)) {
|
if(passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_REFRESH)) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 obtaining access token using refresh token\n");
|
log_message(LOG_PROTOCOL, "OAuth2 obtaining access token using refresh token\n");
|
||||||
OAUTH2Data->refresh_token = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_REFRESH);
|
OAUTH2Data->refresh_token = passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_REFRESH);
|
||||||
ret = oauth2_use_refresh_token (ac_prefs->oauth2_provider, OAUTH2Data);
|
ret = oauth2_use_refresh_token (ac_prefs->oauth2_provider, OAUTH2Data);
|
||||||
}else if (passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_AUTH)) {
|
}else if (passwd_store_has_password(PWS_ACCOUNT, uid, PWS_ACCOUNT_OAUTH2_AUTH)) {
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 trying for fresh access token with auth code\n");
|
log_message(LOG_PROTOCOL, "OAuth2 trying for fresh access token with auth code\n");
|
||||||
ret = oauth2_obtain_tokens (ac_prefs->oauth2_provider, OAUTH2Data,
|
ret = oauth2_obtain_tokens (ac_prefs->oauth2_provider, OAUTH2Data,
|
||||||
passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_AUTH));
|
passwd_store_get_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_AUTH));
|
||||||
}else{
|
}else{
|
||||||
|
@ -545,13 +545,13 @@ gint oauth2_check_passwds (PrefsAccount *ac_prefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret){
|
if (ret){
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token not obtained\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token not obtained\n");
|
||||||
}else{
|
}else{
|
||||||
passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
|
passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
|
||||||
if (ac_prefs->use_smtp_auth && ac_prefs->smtp_auth_type == SMTPAUTH_OAUTH2)
|
if (ac_prefs->use_smtp_auth && ac_prefs->smtp_auth_type == SMTPAUTH_OAUTH2)
|
||||||
passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_SEND, OAUTH2Data->access_token, FALSE);
|
passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_SEND, OAUTH2Data->access_token, FALSE);
|
||||||
passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, OAUTH2Data->expiry_str, FALSE);
|
passwd_store_set_account(ac_prefs->account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, OAUTH2Data->expiry_str, FALSE);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token updated\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token updated\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free(OAUTH2Data);
|
g_free(OAUTH2Data);
|
||||||
|
@ -582,9 +582,9 @@ void oauth2_encode(const gchar *in)
|
||||||
result = g_base64_encode(tmp, len);
|
result = g_base64_encode(tmp, len);
|
||||||
tmp2 = oauth2_decode(result);
|
tmp2 = oauth2_decode(result);
|
||||||
|
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 original: %s\n", in);
|
log_message(LOG_PROTOCOL, "OAuth2 original: %s\n", in);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 encoded: %s\n", result);
|
log_message(LOG_PROTOCOL, "OAuth2 encoded: %s\n", result);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 decoded: %s\n\n", tmp2);
|
log_message(LOG_PROTOCOL, "OAuth2 decoded: %s\n\n", tmp2);
|
||||||
|
|
||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
g_free(tmp2);
|
g_free(tmp2);
|
||||||
|
|
|
@ -1629,7 +1629,7 @@ static void receive_create_widget_func(PrefsPage * _page,
|
||||||
COMBOBOX_ADD (menu2, _("Select"), 0);
|
COMBOBOX_ADD (menu2, _("Select"), 0);
|
||||||
COMBOBOX_ADD (menu2, NULL, 0);
|
COMBOBOX_ADD (menu2, NULL, 0);
|
||||||
COMBOBOX_ADD (menu2, "APOP", POPAUTH_APOP);
|
COMBOBOX_ADD (menu2, "APOP", POPAUTH_APOP);
|
||||||
COMBOBOX_ADD (menu2, "OAUTH2", POPAUTH_OAUTH2);
|
COMBOBOX_ADD (menu2, "OAuth2", POPAUTH_OAUTH2);
|
||||||
|
|
||||||
SET_TOGGLE_SENSITIVITY (pop_auth_checkbtn, vbox5);
|
SET_TOGGLE_SENSITIVITY (pop_auth_checkbtn, vbox5);
|
||||||
|
|
||||||
|
@ -4099,7 +4099,7 @@ static void register_oauth2_page(void)
|
||||||
static gchar *path[3];
|
static gchar *path[3];
|
||||||
|
|
||||||
path[0] = _("Account");
|
path[0] = _("Account");
|
||||||
path[1] = _("OAUTH2");
|
path[1] = _("OAuth2");
|
||||||
path[2] = NULL;
|
path[2] = NULL;
|
||||||
|
|
||||||
oauth2_page.page.path = path;
|
oauth2_page.page.path = path;
|
||||||
|
@ -5154,7 +5154,7 @@ static void prefs_account_oauth2_obtain_tokens(GtkButton *button, gpointer data)
|
||||||
PWS_ACCOUNT_OAUTH2_REFRESH,
|
PWS_ACCOUNT_OAUTH2_REFRESH,
|
||||||
OAUTH2Data->refresh_token,
|
OAUTH2Data->refresh_token,
|
||||||
FALSE);
|
FALSE);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 refresh token stored\n");
|
log_message(LOG_PROTOCOL, "OAuth2 refresh token stored\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(OAUTH2Data->access_token != NULL){
|
if(OAUTH2Data->access_token != NULL){
|
||||||
|
@ -5167,7 +5167,7 @@ static void prefs_account_oauth2_obtain_tokens(GtkButton *button, gpointer data)
|
||||||
PWS_ACCOUNT_SEND,
|
PWS_ACCOUNT_SEND,
|
||||||
OAUTH2Data->access_token,
|
OAUTH2Data->access_token,
|
||||||
FALSE);
|
FALSE);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token stored\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token stored\n");
|
||||||
|
|
||||||
gtk_entry_set_text(GTK_ENTRY(basic_page.pass_entry), OAUTH2Data->access_token);
|
gtk_entry_set_text(GTK_ENTRY(basic_page.pass_entry), OAUTH2Data->access_token);
|
||||||
gtk_entry_set_text(GTK_ENTRY(send_page.smtp_pass_entry), OAUTH2Data->access_token);
|
gtk_entry_set_text(GTK_ENTRY(send_page.smtp_pass_entry), OAUTH2Data->access_token);
|
||||||
|
@ -5178,7 +5178,7 @@ static void prefs_account_oauth2_obtain_tokens(GtkButton *button, gpointer data)
|
||||||
PWS_ACCOUNT_OAUTH2_EXPIRY,
|
PWS_ACCOUNT_OAUTH2_EXPIRY,
|
||||||
OAUTH2Data->expiry_str,
|
OAUTH2Data->expiry_str,
|
||||||
FALSE);
|
FALSE);
|
||||||
log_message(LOG_PROTOCOL, "OAUTH2 access token expiry stored\n");
|
log_message(LOG_PROTOCOL, "OAuth2 access token expiry stored\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_ac_prefs.oauth2_date = g_get_real_time () / G_USEC_PER_SEC;
|
tmp_ac_prefs.oauth2_date = g_get_real_time () / G_USEC_PER_SEC;
|
||||||
|
|
|
@ -136,7 +136,7 @@ struct _PrefsAccount
|
||||||
|
|
||||||
GSList *customhdr_list;
|
GSList *customhdr_list;
|
||||||
|
|
||||||
/* OAUTH2 */
|
/* OAuth2 */
|
||||||
gint oauth2_provider;
|
gint oauth2_provider;
|
||||||
gint oauth2_date;
|
gint oauth2_date;
|
||||||
gchar *oauth2_authcode;
|
gchar *oauth2_authcode;
|
||||||
|
|
|
@ -144,7 +144,7 @@ static void _update_config_account(PrefsAccount *ac_prefs, gint version)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
/* With the introduction of OAUTH2 support, the APOP option
|
/* With the introduction of OAuth2 support, the APOP option
|
||||||
* (use_apop_auth) has been swallowed into a combobox and
|
* (use_apop_auth) has been swallowed into a combobox and
|
||||||
* renamed */
|
* renamed */
|
||||||
if (ac_prefs->use_apop_auth == 1) {
|
if (ac_prefs->use_apop_auth == 1) {
|
||||||
|
|
Loading…
Reference in a new issue