Skip to content

Commit aef754d

Browse files
committed
feature(examples): configure managesieve and test oidc authentication in oidc example
1 parent 49dbb94 commit aef754d

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

examples/oidc/README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,4 +189,35 @@ We would use Thunderbird version 91.4.1 as a mail client (above versions should
189189
![](_media/receive-mail.png)
190190

191191
A remark here is that if you generate a new client_secret for `james-thunderbird` client in Keycloak, you have to modify
192-
it accordingly in `OAuth2Providers.jsm`.
192+
it accordingly in `OAuth2Providers.jsm`.
193+
194+
### IMAP on the CLI
195+
196+
You can test logging into IMAP on the CLI by connecting with `telnet localhost 143`. Here are some commands that can be tried:
197+
198+
- `a AUTHENTICATE XOAUTH2 <initial response>` (unauthenticated state)
199+
- `b AUTHENTICATE OAUTHBEARER <initial response>` (unauthenticated state)
200+
- `c LOGOUT` (any state)
201+
202+
You can get the initial response from the [test script](./test.sh).
203+
204+
### ManageSieve on the CLI
205+
206+
You can test logging into IMAP on the CLI by connecting with `telnet localhost 4190`. Here are some commands that can be tried:
207+
208+
- `AUTHENTICATE "XOAUTH2" "<initial response>"` (unauthenticated state)
209+
- `AUTHENTICATE "OAUTHBEARER" "<initial response>"` (unauthenticated state)
210+
- `CAPABILITY` (any state)
211+
- `LOGOUT` (any state)
212+
213+
You can get the initial response from the [test script](./test.sh).
214+
215+
### SMTP on the CLI
216+
217+
You can test logging into IMAP on the CLI by connecting with `telnet localhost 587`. Here are some commands that can be tried:
218+
219+
- `AUTH XOAUTH2 <initial response>` (unauthenticated state)
220+
- `AUTH OAUTHBEARER <initial response>` (unauthenticated state)
221+
- `QUIT` (any state)
222+
223+
You can get the initial response from the [test script](./test.sh).

examples/oidc/docker-compose.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ services:
2929
- ./james/jmap.properties:/root/conf/jmap.properties
3030
- ./james/imapserver.xml:/root/conf/imapserver.xml
3131
- ./james/smtpserver.xml:/root/conf/smtpserver.xml
32+
- ./james/managesieveserver.xml:/root/conf/managesieveserver.xml
3233
ports:
3334
- "8000:8000"
35+
- "143:143"
36+
- "587:587"
37+
- "4190:4190"
3438
healthcheck:
3539
test: ["CMD", "curl", "-f", "http://james:8000/domains"]
3640

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0"?>
2+
<managesieveservers>
3+
<managesieveserver enabled="true">
4+
<jmxName>managesieveserver</jmxName>
5+
<bind>0.0.0.0:4190</bind>
6+
<connectionBacklog>200</connectionBacklog>
7+
<connectiontimeout>360</connectiontimeout>
8+
<connectionLimit>0</connectionLimit>
9+
<connectionLimitPerIP>0</connectionLimitPerIP>
10+
<oidc>
11+
<oidcConfigurationURL>http://sso.example.com:8080/auth/realms/oidc/.well-known/openid-configuration</oidcConfigurationURL>
12+
<jwksURL>http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/certs</jwksURL>
13+
<claim>email</claim>
14+
<scope>openid profile email</scope>
15+
<introspection>
16+
<url>http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/token/introspect</url>
17+
<auth>Basic amFtZXMtdGh1bmRlcmJpcmQ6WHc5aHQxdmVUdTBUazVzTU15MDNQZHpZM0FpRnZzc3c=</auth>
18+
</introspection>
19+
</oidc>
20+
</managesieveserver>
21+
</managesieveservers>

examples/oidc/test.sh

100644100755
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,47 @@ else
3232
echo "Not OK"
3333
fi
3434

35+
XOAUTH2_INITIAL_CLIENT_RESPONSE=`echo -n -e "user=james-user@localhost\x01auth=Bearer ${ACCESS_TOKEN}\x01\x01" | base64 -w 0`
36+
OAUTHBEARER_INITIAL_CLIENT_RESPONSE=`echo -n -e "n,a=james-user@localhost\x01auth=Bearer ${ACCESS_TOKEN}\x01\x01" | base64 -w 0`
37+
38+
set +x
39+
MANAGESIEVE_XOAUTH2_RESPONSE=`(echo "AUTHENTICATE \"XOAUTH2\" \"${XOAUTH2_INITIAL_CLIENT_RESPONSE}\""; echo "CAPABILITY"; echo "LOGOUT"; sleep 3) | telnet localhost 4190`
40+
if echo $MANAGESIEVE_XOAUTH2_RESPONSE | grep "\"OWNER\" \"james-user@localhost\"" > /dev/null; then
41+
echo "Success: Managesieve XOAUTH2 login"
42+
else
43+
echo "Error: Managesieve XOAUTH2 login"
44+
fi
45+
if echo $MANAGESIEVE_XOAUTH2_RESPONSE | grep "OK channel is closing" > /dev/null; then
46+
echo "Success: Managesieve XOAUTH2 logout"
47+
else
48+
echo "Error: Managesieve XOAUTH2 logout"
49+
fi
50+
51+
IMAP_XOAUTH2_RESPONSE=`(echo "a AUTHENTICATE XOAUTH2 ${XOAUTH2_INITIAL_CLIENT_RESPONSE}"; echo "c LOGOUT"; sleep 3) | telnet localhost 143`
52+
if echo $IMAP_XOAUTH2_RESPONSE | grep "a OK AUTHENTICATE completed" > /dev/null; then
53+
echo "Success: IMAP XOAUTH2 login"
54+
else
55+
echo "Error: IMAP XOAUTH2 login"
56+
fi
57+
if echo $IMAP_XOAUTH2_RESPONSE | grep "c OK LOGOUT completed" > /dev/null; then
58+
echo "Success: IMAP XOAUTH2 logout"
59+
else
60+
echo "Error: IMAP XOAUTH2 logout"
61+
fi
62+
63+
SMTP_XOAUTH2_RESPONSE=`(echo "AUTH XOAUTH2 ${XOAUTH2_INITIAL_CLIENT_RESPONSE}"; echo "QUIT"; sleep 3) | telnet localhost 587`
64+
if echo $SMTP_XOAUTH2_RESPONSE | grep "235 Authentication successful" > /dev/null; then
65+
echo "Success: SMTP XOAUTH2 login"
66+
else
67+
echo "Error: SMTP XOAUTH2 login"
68+
fi
69+
if echo $SMTP_XOAUTH2_RESPONSE | grep "221 2.0.0 james.local Service closing transmission channel" > /dev/null; then
70+
echo "Success: SMTP XOAUTH2 logout"
71+
else
72+
echo "Error: SMTP XOAUTH2 logout"
73+
fi
74+
set -x
75+
3576
# Logout
3677

3778
curl --location 'http://sso.example.com:8080/auth/realms/oidc/protocol/openid-connect/logout' \

0 commit comments

Comments
 (0)