* Add support for the OAUTHBEARER authentication method in Gmail. Thanks to
[alpine.git] / imap / src / c-client / auth_ext.c
blobb85f6bbfc5923ba49af494948d0803120524a49a
1 /* ========================================================================
2 * Copyright 2020 Eduardo Chappa
3 * Copyright 1988-2006 University of Washington
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
12 * ========================================================================
16 * Program: EXTERNAL authenticator
18 * Author: Mark Crispin
19 * Networks and Distributed Computing
20 * Computing & Communications
21 * University of Washington
22 * Administration Building, AG-44
23 * Seattle, WA 98195
24 * Internet: MRC@CAC.Washington.EDU
26 * Date: 6 April 2005
27 * Last Edited: 30 August 2006
30 long auth_external_client (authchallenge_t challenger,authrespond_t responder,
31 char *service,NETMBX *mb,void *stream, unsigned long port,
32 unsigned long *trial,char *user);
33 char *auth_external_server (authresponse_t responder,int argc,char *argv[]);
35 AUTHENTICATOR auth_ext = { /* secure, has full auth, hidden */
36 AU_SECURE | AU_AUTHUSER | AU_HIDE,
37 "EXTERNAL", /* authenticator name */
38 NIL, /* always valid */
39 auth_external_client, /* client method */
40 auth_external_server, /* server method */
41 NIL /* next authenticator */
44 /* Client authenticator
45 * Accepts: challenger function
46 * responder function
47 * SASL service name
48 * parsed network mailbox structure
49 * stream argument for functions
50 * pointer to current trial count
51 * returned user name
52 * Returns: T if success, NIL otherwise, number of trials incremented if retry
55 long auth_external_client (authchallenge_t challenger,authrespond_t responder,
56 char *service,NETMBX *mb,void *stream, unsigned long port,
57 unsigned long *trial,char *user)
59 void *challenge;
60 unsigned long clen;
61 long ret = NIL;
62 *trial = 65535; /* never retry */
63 if ((challenge = (*challenger) (stream,&clen)) != NULL) {
64 fs_give ((void **) &challenge);
65 /* send authorization id (empty string OK) */
66 if ((*responder) (stream,strcpy (user,mb->user),strlen (mb->user))) {
67 if ((challenge = (*challenger) (stream,&clen)) != NULL)
68 fs_give ((void **) &challenge);
69 else ret = LONGT; /* check the authentication */
72 return ret;
76 /* Server authenticator
77 * Accepts: responder function
78 * argument count
79 * argument vector
80 * Returns: authenticated user name or NIL
83 char *auth_external_server (authresponse_t responder,int argc,char *argv[])
85 unsigned long len;
86 char *authid;
87 char *authenid = (char *) mail_parameters (NIL,GET_EXTERNALAUTHID,NIL);
88 char *ret = NIL;
89 /* get authorization identity */
90 if (authenid && (authid = (*responder) ("",0,&len))) {
91 /* note: responders null-terminate */
92 if (*authid ? authserver_login (authid,authenid,argc,argv) :
93 authserver_login (authenid,NIL,argc,argv)) ret = myusername ();
94 fs_give ((void **) &authid);
96 return ret;