rewind. If the need should arise when uploading from stdin, the upload
operation will fail.
.IP "--bearer"
-(IMAP/SMTP) Specify the Bearer Token for OAUTH 2.0 server authentication. The
-Bearer Token is used in conjuction with the user name which can be specified
-as part of the \fI--url\fP option or the \fI-u, --user\fP option.
+(IMAP/POP3/SMTP) Specify the Bearer Token for OAUTH 2.0 server authentication.
+The Bearer Token is used in conjuction with the user name which can be
+specified as part of the \fI--url\fP or \fI-u, --user\fP options.
The Bearer Token and user name are formatted according to RFC 6750.
* RFC4422 Simple Authentication and Security Layer (SASL)
* RFC4616 PLAIN authentication
* RFC5034 POP3 SASL Authentication Mechanism
+ * RFC6749 OAuth 2.0 Authorization Framework
*
***************************************************************************/
pop3c->authmechs |= SASL_MECH_EXTERNAL;
else if(wordlen == 4 && !memcmp(line, "NTLM", 4))
pop3c->authmechs |= SASL_MECH_NTLM;
+ else if(wordlen == 7 && !memcmp(line, "XOAUTH2", 7))
+ pop3c->authmechs |= SASL_MECH_XOAUTH2;
line += wordlen;
len -= wordlen;
"AUTH_DIGESTMD5_RESP",
"AUTH_NTLM",
"AUTH_NTLM_TYPE2MSG",
+ "AUTH_XOAUTH2",
"AUTH_FINAL",
"APOP",
"USER",
}
else
#endif
- if((pop3c->authmechs & SASL_MECH_LOGIN) &&
+ if(((pop3c->authmechs & SASL_MECH_XOAUTH2) &&
+ (pop3c->prefmech & SASL_MECH_XOAUTH2) &&
+ (pop3c->prefmech != SASL_AUTH_ANY)) || conn->xoauth2_bearer) {
+ mech = "XOAUTH2";
+ state1 = POP3_AUTH_XOAUTH2;
+ state2 = POP3_AUTH_FINAL;
+ pop3c->authused = SASL_MECH_XOAUTH2;
+
+ if(data->set.sasl_ir)
+ result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
+ conn->xoauth2_bearer,
+ &initresp, &len);
+ }
+ else if((pop3c->authmechs & SASL_MECH_LOGIN) &&
(pop3c->prefmech & SASL_MECH_LOGIN)) {
mech = "LOGIN";
state1 = POP3_AUTH_LOGIN;
}
#endif
+/* For AUTH XOAUTH2 (without initial response) responses */
+static CURLcode pop3_state_auth_xoauth2_resp(struct connectdata *conn,
+ int pop3code, pop3state instate)
+{
+ CURLcode result = CURLE_OK;
+ struct SessionHandle *data = conn->data;
+ size_t len = 0;
+ char *xoauth = NULL;
+
+ (void)instate; /* no use for this yet */
+
+ if(pop3code != '+') {
+ failf(data, "Access denied: %d", pop3code);
+ result = CURLE_LOGIN_DENIED;
+ }
+ else {
+ /* Create the authorisation message */
+ result = Curl_sasl_create_xoauth2_message(conn->data, conn->user,
+ conn->xoauth2_bearer,
+ &xoauth, &len);
+
+ /* Send the message */
+ if(!result) {
+ if(xoauth) {
+ result = Curl_pp_sendf(&conn->proto.pop3c.pp, "%s", xoauth);
+
+ if(!result)
+ state(conn, POP3_AUTH_FINAL);
+ }
+
+ Curl_safefree(xoauth);
+ }
+ }
+
+ return result;
+}
+
/* For final responses to the AUTH sequence */
static CURLcode pop3_state_auth_final_resp(struct connectdata *conn,
int pop3code,
break;
#endif
+ case POP3_AUTH_XOAUTH2:
+ result = pop3_state_auth_xoauth2_resp(conn, pop3code, pop3c->state);
+ break;
+
case POP3_AUTH_FINAL:
result = pop3_state_auth_final_resp(conn, pop3code, pop3c->state);
break;
pop3c->preftype = POP3_TYPE_SASL;
pop3c->prefmech = SASL_MECH_NTLM;
}
+ else if(strequal(value, "XOAUTH2")) {
+ pop3c->preftype = POP3_TYPE_SASL;
+ pop3c->prefmech = SASL_MECH_XOAUTH2;
+ }
else {
pop3c->preftype = POP3_TYPE_NONE;
pop3c->prefmech = SASL_AUTH_NONE;
" --anyauth Pick \"any\" authentication method (H)",
" -a, --append Append to target file when uploading (F/SFTP)",
" --basic Use HTTP Basic Authentication (H)",
- " --bearer BEARER XOAUTH2 Bearer Token (IMAP and SMTP)",
+ " --bearer BEARER XOAUTH2 Bearer Token (IMAP, POP3, SMTP)",
" --cacert FILE CA certificate to verify peer against (SSL)",
" --capath DIR CA directory to verify peer against (SSL)",
" -E, --cert CERT[:PASSWD] Client certificate file and password (SSL)",