You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by GitBox <gi...@apache.org> on 2021/12/15 02:07:32 UTC
[GitHub] [james-project] vttranlina opened a new pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
vttranlina opened a new pull request #796:
URL: https://github.com/apache/james-project/pull/796
Ref: https://issues.apache.org/jira/browse/JAMES-3680
https://github.com/linagora/james-project/issues/4436
This PR in progress
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773555484
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
##########
@@ -130,6 +130,7 @@ public static HumanReadableText permanentFlags(Flags flags) {
public static final HumanReadableText BAD_IO_ENCODING = new HumanReadableText("org.apache.james.imap.BAD_IO_ENCODING", "failed. Illegal encoding.");
public static final HumanReadableText COMPLETED = new HumanReadableText("org.apache.james.imap.COMPLETED", "completed.");
+ public static final HumanReadableText SUCCEEDED = new HumanReadableText("org.apache.james.imap.SUCCEEDED", "succeeded.");
Review comment:
Yes but `t1 OK SASL authentication completed` is good too.
We don't need to have comment messages matching 100% ;-)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773599993
##########
File path: server/protocols/jwt/src/test/java/org/apache/james/jwt/OidcJwksPublicKeyProviderTest.java
##########
@@ -0,0 +1,121 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.security.PublicKey;
+import java.security.interfaces.RSAPublicKey;
+import java.util.List;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.HttpRequest;
+import org.mockserver.model.HttpResponse;
+
+class OidcJwksPublicKeyProviderTest {
+ private static final String JWKS_URI_PATH = "/auth/realms/realm1/protocol/openid-connect/certs";
+ private static final String JWKS_JSON = "{" +
+ " \"keys\": [" +
+ " {" +
+ " \"kid\": \"QgjozGKW0m9NV3Gw-AdYbjyZsBd6VATHCkY8bcraewA\"," +
+ " \"kty\": \"RSA\"," +
+ " \"alg\": \"RS256\"," +
+ " \"use\": \"enc\"," +
+ " \"n\": \"jW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SKal/kStl4RwmSoIOM/0jjbEHJF9hDxrQ5va/fH6dUXxwjC5wI1tESk+dadJfuwmRZ2pVChzJSkLuqBz2xPwDz31iuAiZLFDRlHgIOVxfIx8FxlNFrxrp5QF2B7lbnEfMh20QiOACizxt/ghn3gmz/J5zitXl1g5/cnnr5cHG+D1eboKELu7qHCBgf3/pHyTlbrOJh6EqCqpntiCz/XKepTmG3CjM+pyml/OnYaMcVXBsmLSalFco4HPsqMKjKY+KEL9N0sCKTY9BxlwigRrtcPzKqH6orZVTBXlRXK9IWpEmCKoR5cVIxi3ctAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAIEb/zH5YIMVL3gM/w8DnVNhFTBeZ1GUaz5uWsXmlc3aC6Lshl5lJYH27gy41bIwvQspDPsHw9h69VnN2I5aoVomJ4re94LxorxC7767mINUnwrwClhyNO1bdZWi6zeKp+pwVhBymazeXL5SV2ngBrsFZrQ7XtfhxDqRy69gFJQwJXwhD/qfhgBj+jcsYGFpvooGGLoOpc5f6gzkTv1u99NqwWSj7E4yfrcBjlrQafUdsD4nD4cSNi2Lqd7dRmCvhgIjzFOuBpEqVSgoQIwlja9Gc8hA6DVcxvZiE6q2sMzjp8Orxgl3UqqqR+Pb0ITqfM5OQLZF+nCIhryF/ZCChVM=\"" +
+ " ]," +
+ " \"x5t\": \"paqnI4t1-GuJz5PUqtTgfLjXcqw\"," +
+ " \"x5t#S256\": \"S3QfJleq8olDM3dXMb2GI2jGM_Ntdt040JOANmEGEh8\"" +
+ " }" +
+ " ]" +
+ "}";
+
+ ClientAndServer mockServer;
+
+ @BeforeEach
+ public void setUp() {
+ mockServer = ClientAndServer.startClientAndServer(0);
+ mockServer
+ .when(HttpRequest.request().withPath(JWKS_URI_PATH))
+ .respond(HttpResponse.response().withStatusCode(200)
+ .withHeader("Content-Type","application/json")
+ .withBody(JWKS_JSON, StandardCharsets.UTF_8));
+ }
+
+ private URL getJwksURL() {
+ try {
+ return new URL(String.format("http://127.0.0.1:%s%s", mockServer.getLocalPort(), JWKS_URI_PATH));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Test
+ void getShouldSuccessWhenKeyProvided() {
+ PublicKeyProvider testee = new OidcJwksPublicKeyProvider(getJwksURL(), "wu-9VZEr0gHF986PYPVzvU-5IP1q26EzzQVK_sjG29Q");
+ List<PublicKey> publicKeys = testee.get();
+ SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(publicKeys).hasSize(1);
+ softly.assertThat(publicKeys.get(0)).isInstanceOf(RSAPublicKey.class);
+ });
+ }
+
+ @Test
+ void getShouldReturnEmptyWhenKeyNotProvided() {
+ PublicKeyProvider testee = new OidcJwksPublicKeyProvider(getJwksURL(), "notfound");
+ assertThat(testee.get()).isEmpty();
+ }
+
+ @Test
+ void getShouldFailWhenBadJwksURL() throws MalformedURLException {
+ mockServer
+ .when(HttpRequest.request().withPath("/invalid"))
+ .respond(HttpResponse.response().withStatusCode(200)
+ .withBody("invalid body", StandardCharsets.UTF_8));
+
+ PublicKeyProvider testee = new OidcJwksPublicKeyProvider(new URL(String.format("http://127.0.0.1:%s/invalid", mockServer.getLocalPort())),
+ "wu-9VZEr0gHF986PYPVzvU-5IP1q26EzzQVK_sjG29Q");
Review comment:
No,
this is "bad url" for `getShouldFailWhenBadJwksURL`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773551798
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/OidcJwtTokenVerifier.java
##########
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.net.URL;
+import java.util.Optional;
+
+public class OidcJwtTokenVerifier {
+
+ public Optional<String> verifyAndExtractClaim(String jwtToken, URL jwksURL, String claimName) {
+ PublicKeyProvider jwksPublicKeyProvider = JwtTokenHelper.getClaimWithoutSignatureVerification(jwtToken, "kid", String.class)
Review comment:
I think it will be re-use in SMTP Oauth?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769202100
##########
File path: protocols/api/src/main/java/org/apache/james/protocols/api/OidcSASLConfiguration.java
##########
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+import java.net.URL;
+
+public class OidcSASLConfiguration {
+ private final URL jwksURL;
+ private final String claim;
+ private final URL oidcConfigurationURL;
Review comment:
We need `oidcConfigurationURL` as it need to be returned upon errors to the client.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa edited a comment on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa edited a comment on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005419846
> Adding manually at thunderbird path /thunderbird/omni.ja/OAuth2Providers.jsm
Can you share your exact content for this demo?
Also what is your version of Thunderbird?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r770507636
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
Review comment:
Yes that's ok.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773555713
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/OidcJwtTokenVerifier.java
##########
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.net.URL;
+import java.util.Optional;
+
+public class OidcJwtTokenVerifier {
+
+ public Optional<String> verifyAndExtractClaim(String jwtToken, URL jwksURL, String claimName) {
+ PublicKeyProvider jwksPublicKeyProvider = JwtTokenHelper.getClaimWithoutSignatureVerification(jwtToken, "kid", String.class)
Review comment:
IMO it will be having the exact same call path than IMAP.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa merged pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa merged pull request #796:
URL: https://github.com/apache/james-project/pull/796
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769239117
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
> As a record, Keycloack tokens might not contain kid.
From what I could see on preprod we have... However regarding the specs: https://openid.net/specs/openid-connect-core-1_0.html#Signing
```
If there are multiple keys in the referenced JWK Set document, a kid value MUST be provided in the JOSE Header.
```
If only one key is referenced, then it seems optional. But if we have more than one key it's required.
```
I had problems with kid too but calling the JWKS provider with a null kid takes the first public key of the jwks URI and does the job.
```
If for reason X or Y there is multiple keys referenced by Keycloak that's bound to be a problem no?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] quantranhong1999 commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r770427862
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+ session.authenticated();
+ session.setMailboxSession(mailboxSession);
+ okComplete(request, responder);
+ } catch (AddressException e) {
+ LOGGER.error("Error encountered while login. mail address is invalid, {}", claim.get(), e);
Review comment:
I see in https://github.com/apache/james-project/pull/784/commits/f0806a65a1e4f47be076afae3c3fd16f6e79bc78, if the jwt is verified we just then create the session directly.
Not really sure about this too, hope to get another ans.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005419846
> Adding manually at thunderbird path /thunderbird/omni.ja/OAuth2Providers.jsm
Can you share your exact content for this demo?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005424929
`ffmpeg -i OAUTH_IMAP_JAMES.mp4 OAUTH_IMAP_JAMES_re-encoded.mp4`
https://user-images.githubusercontent.com/6928740/148172705-f66ec8a1-680a-4032-a3ca-0ebce4111237.mp4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r770509324
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+ session.authenticated();
+ session.setMailboxSession(mailboxSession);
+ okComplete(request, responder);
+ } catch (AddressException e) {
+ LOGGER.error("Error encountered while login. mail address is invalid, {}", claim.get(), e);
Review comment:
I agree adding a check to the users repository.
An alternative could be "auto-provisionning" : creating the user on its first interaction, but it seems overkill to me...
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
Review comment:
Remove final qualifier usages for variables
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769241765
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
This is a jwks_uri response (from keycloak)
```
{
"keys": [
{
"kid": "LKWz5vXAObZAzwep-0HunIjkZKMavkHwtC3W5l6uhFc",
"kty": "RSA",
"alg": "RS256",
"use": "sig",
"n": "uml4553PpIDNjoOB-G29xVrQfIzVkg2mACa7aT876i20RdFXxE4qxwczJqh4yw4hAgv0Vv_m2a9m9gWaK7fmytAxWG5jtzT9AM4hLDuGhTwiIs9rW3BMnwfPWtO2aVgTekVCZ5xAyH4_K0ov6Ud0VPQPjaTbWrj7XX03clNTlV54E28cBfyLtbt0z2Su8aer8kc_dxgM2aJ0U84nCOHCmmDPLT69VzM56NWRklRG1RYwTMZm4edZJRgUcz0enGxHEhvTLMkFky9J3l_NIdwT76UuZnOP25hzOetF2s35BgH9TbplSxkt-mJ9UDyGhHJEypRuQYSsHb0ZaAFGHe2m8Q",
"e": "AQAB",
"x5c": [
"MIICmzCCAYMCBgF9uij8bTANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDDAZyZWFsbTEwHhcNMjExMjE0MTgxNDQ4WhcNMzExMjE0MTgxNjI4WjARMQ8wDQYDVQQDDAZyZWFsbTEwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC6aXjnnc+kgM2Og4H4bb3FWtB8jNWSDaYAJrtpPzvqLbRF0VfETirHBzMmqHjLDiECC/RW/+bZr2b2BZort+bK0DFYbmO3NP0AziEsO4aFPCIiz2tbcEyfB89a07ZpWBN6RUJnnEDIfj8rSi/pR3RU9A+NpNtauPtdfTdyU1OVXngTbxwF/Iu1u3TPZK7xp6vyRz93GAzZonRTzicI4cKaYM8tPr1XMzno1ZGSVEbVFjBMxmbh51klGBRzPR6cbEcSG9MsyQWTL0neX80h3BPvpS5mc4/bmHM560XazfkGAf1NumVLGS36Yn1QPIaEckTKlG5BhKwdvRloAUYd7abxAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAJ4SA0Hqc5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FAJjyoQODUeYMsULQYJ6j58MXpYqQpncFm/OWXWpC+5XruCqU4RTXcYV+vvi85D3wL7yLP/2n2+4wrHXDiY8mof6a9DaHQANkGlOQOTsJEcrnEM/R3PBlUb3NUmu7qnRSdbqOA4DiXWVwxdwBslfSTJhEvawLp1QWyx231bTEn3ou/WO++Y4WhLH8LaAUXCHpRvny2YchChkE72ndlvjK3T1dwQL0yrj7AekxS+GC77x2180IFFRHPtmA9IJ8GrfC0UeGpJDUp86jKb+rYcJOMUSQvqXMHs0iQjjm3DOEjY3Zhtwh97hIjdiy3X5+3Fotw161XXP36rO/95DAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAD5+8dGYI4abh8HZrGvlaDvPI5uMX6oD7hnHzGxcWnzyR/aGZj1P4OeWHgYQ/K9jE5gAtCB52rdBLld4EUM7wA2NEV74Z8OGSasoSKXtrE+wUbbmxQlekFvVAJWZLjuzMiKfhwR7mMW+4Tq4DGsSSZoLBVx29gohtC4O9XMSO5iocq+k+mm0DSwi9RyFmjo0mChGr4KOM6wd/HCVo5DtniaHgurhguxZDmxHpA/Bf74WcctKsdUeSEPp58bZZ3qtW89G0wWnTuqeu5AgW2JMm3Can2xofd1dq1/CdLlkmOZO6/LJelPL6/UEfAXSd60Ya8qZScCmo+VpTpeTiWC2MUI="
],
"x5t": "xXOwsNLjTmoTzy6uF1lyaFx4QGw",
"x5t#S256": "wffP6FO_XinFVv5hmtXymG85jqIOtO12m5XdJmC4RU0"
}
]
}
```
We can create more publicKey if we want
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773543986
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
##########
@@ -130,6 +130,7 @@ public static HumanReadableText permanentFlags(Flags flags) {
public static final HumanReadableText BAD_IO_ENCODING = new HumanReadableText("org.apache.james.imap.BAD_IO_ENCODING", "failed. Illegal encoding.");
public static final HumanReadableText COMPLETED = new HumanReadableText("org.apache.james.imap.COMPLETED", "completed.");
+ public static final HumanReadableText SUCCEEDED = new HumanReadableText("org.apache.james.imap.SUCCEEDED", "succeeded.");
Review comment:
IMO both are the same. Why introduce a new one?
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractMailboxProcessor.java
##########
@@ -332,6 +332,11 @@ protected void okComplete(ImapRequest request, ResponseCode code, ImapProcessor
responder.respond(response);
}
+ protected void okSuccess(ImapRequest request, ImapProcessor.Responder responder) {
+ final StatusResponse response = factory.taggedOk(request.getTag(), request.getCommand(), HumanReadableText.SUCCEEDED);
Review comment:
```suggestion
StatusResponse response = factory.taggedOk(request.getTag(), request.getCommand(), HumanReadableText.SUCCEEDED);
```
Avoid final qualifier on variables.
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/OidcJwksPublicKeyProvider.java
##########
@@ -0,0 +1,87 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.net.URL;
+import java.security.PublicKey;
+import java.util.List;
+import java.util.Optional;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.auth0.jwk.Jwk;
+import com.auth0.jwk.JwkException;
+import com.auth0.jwk.SigningKeyNotFoundException;
+import com.auth0.jwk.UrlJwkProvider;
+import com.github.fge.lambdas.Throwing;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+
+public class OidcJwksPublicKeyProvider implements PublicKeyProvider {
Review comment:
```suggestion
public class JwksPublicKeyProvider implements PublicKeyProvider {
```
##########
File path: server/protocols/protocols-imap4/src/test/java/org/apache/james/imapserver/netty/IMAPServerTest.java
##########
@@ -615,6 +628,120 @@ void loginShouldSuccessWhenNOTRequireSSLAndEncryptedChannel() throws Exception {
}
}
+ @Nested
+ class Oauth {
+ String JWKS_URI_PATH = "/jwks";
+ ClientAndServer authServer;
+ IMAPServer imapServer;
+ int port;
+
+ @BeforeEach
+ void authSetup() throws Exception {
+ authServer = ClientAndServer.startClientAndServer(0);
+ authServer
+ .when(HttpRequest.request().withPath(JWKS_URI_PATH))
+ .respond(HttpResponse.response().withStatusCode(200)
+ .withHeader("Content-Type", "application/json")
+ .withBody(OidcTokenFixture.JWKS_RESPONSE, StandardCharsets.UTF_8));
+
+ HierarchicalConfiguration<ImmutableNode> config = ConfigLoader.getConfig(ClassLoaderUtils.getSystemResourceAsSharedStream("imapServerRequireSSLIsTrueAndStartSSLIsTrue.xml"));
+ config.addProperty("auth.oauth.jwksURL", String.format("http://127.0.0.1:%s%s", authServer.getLocalPort(), JWKS_URI_PATH));
+ config.addProperty("auth.oauth.claim", OidcTokenFixture.CLAIM);
+ config.addProperty("auth.oauth.oidcConfigurationURL", "https://example.com/jwks");
+ config.addProperty("auth.oauth.scope", "read");
+ imapServer = createImapServer(config);
+ port = imapServer.getListenAddresses().get(0).getPort();
+ }
+
+ @AfterEach
+ void tearDown() {
+ if (imapServer != null) {
+ imapServer.destroy();
+ }
+ }
Review comment:
We don't need to stop the authServer ?
##########
File path: protocols/api/src/test/java/org/apache/james/protocols/api/OIDCSASLParserTest.java
##########
@@ -0,0 +1,148 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import com.google.common.collect.ImmutableList;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class OIDCSASLParserTest {
+ static String BEARER = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ1RXNWV3hOckQxU3BJWUxZQzU5bWN0Q19ESHM1aFFfN0N1Tkd3YjJSWkVBIn0.eyJleHAiOjE2Mzk1NTUxMDgsImlhdCI6MTYzOTU1MTUwOCwiYXV0aF90aW1lIjoxNjM5NTUxNTA2LCJqdGkiOiIxYjVlMGRlMi04MjNhLTQxZDMtOTU2Mi0xMzk5N2U5YWNmMjYiLCJpc3MiOiJodHRwczovL2F1dGgudXBuLmludGVncmF0aW9uLW9wZW4tcGFhcy5vcmcvYXV0aC9yZWFsbXMvdXBuIiwiYXVkIjoiYWNjb3Vud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r7YgvlpJTlPC2F-Bn0vtLeIu1iH5KLEhla3ospIjSeuseClqAE-_1ze7BUqJHyKUrpc2b5N84wzQA";
+ static char del = 1;
Review comment:
DELIMITER
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/OidcJwtTokenVerifier.java
##########
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.net.URL;
+import java.util.Optional;
+
+public class OidcJwtTokenVerifier {
+
+ public Optional<String> verifyAndExtractClaim(String jwtToken, URL jwksURL, String claimName) {
Review comment:
BTW no tests on `kid` retrieval?
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +174,37 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String initialResponse, ImapSession session, ImapRequest request, Responder responder) {
+ if (session.oidcSaslConfiguration().isEmpty()) {
+ no(request, responder, HumanReadableText.UNSUPPORTED_AUTHENTICATION_MECHANISM);
+ } else {
+ OIDCSASLParser.parse(initialResponse)
+ .flatMap(oidcInitialResponseValue -> {
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
Review comment:
Extract this line out of the flatMap block please...
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/OidcJwtTokenVerifier.java
##########
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.net.URL;
+import java.util.Optional;
+
+public class OidcJwtTokenVerifier {
+
+ public Optional<String> verifyAndExtractClaim(String jwtToken, URL jwksURL, String claimName) {
+ PublicKeyProvider jwksPublicKeyProvider = JwtTokenHelper.getClaimWithoutSignatureVerification(jwtToken, "kid", String.class)
Review comment:
Can we move `getClaimWithoutSignatureVerification` to this class ?
(I do not think we need a helper class.)
##########
File path: protocols/api/src/test/java/org/apache/james/protocols/api/OIDCSASLParserTest.java
##########
@@ -0,0 +1,148 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+import com.google.common.collect.ImmutableList;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class OIDCSASLParserTest {
+ static String BEARER = "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJ1RXNWV3hOckQxU3BJWUxZQzU5bWN0Q19ESHM1aFFfN0N1Tkd3YjJSWkVBIn0.eyJleHAiOjE2Mzk1NTUxMDgsImlhdCI6MTYzOTU1MTUwOCwiYXV0aF90aW1lIjoxNjM5NTUxNTA2LCJqdGkiOiIxYjVlMGRlMi04MjNhLTQxZDMtOTU2Mi0xMzk5N2U5YWNmMjYiLCJpc3MiOiJodHRwczovL2F1dGgudXBuLmludGVncmF0aW9uLW9wZW4tcGFhcy5vcmcvYXV0aC9yZWFsbXMvdXBuIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6IjIzZTBlZjg3LTZhYTMtNDdkYS1hY2NiLTI5YzU4OGQyYzFkOSIsInR5cCI6IkJlYXJlciIsImF6cCI6Im9wZW5wYWFzIiwic2Vzc2lvbl9zdGF0ZSI6ImQ3YzI5NjJmLTYyYmEtNDQ5YS04ZmFjLTI5YTU2ZGJmNjZiMCIsImFjciI6IjEiLCJhbGxvd2VkLW9yaWdpbnMiOlsiKiJdLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsImRlZmF1bHQtcm9sZXMtdXBuIl19LCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIiwidmlldy1wcm9maWxlIl19fSwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwibmFtZSI6IkZpcnN0bmFtZTE0IFN1cm5hbWUxNCIsInByZWZlcnJlZF91c2VybmFtZS
I6ImZpcnN0bmFtZTE0LnN1cm5hbWUxNCIsImdpdmVuX25hbWUiOiJGaXJzdG5hbWUxNCIsImZhbWlseV9uYW1lIjoiU3VybmFtZTE0IiwiZW1haWwiOiJmaXJzdG5hbWUxNC5zdXJuYW1lMTRAdXBuLmludGVncmF0aW9uLW9wZW4tcGFhcy5vcmcifQ.VdAgJ9OnLSlya0gC0AAoP23fv20Etoz73lAGcNNNj1OM5eLuenAM7m06uKKLTtX4pqbIYRS0JrMaSRWnxO-BWnJdE3KhF5SPGzuTZStLoMnQpOZMZK5qlejD7DaWky6CvyCcXPDmo8er7c_dk6OGKAXOPwWdLsyCBEFL3CE3wDegG3ZivTk-9kXcTAHx_-47MHOXca6zwyjrRW3g-bdhEzNqCEsgTs8wo3v9sIxFVfo_RFVVOzOG4QpVJOIFrTwgFv3FKiiJyr7YgvlpJTlPC2F-Bn0vtLeIu1iH5KLEhla3ospIjSeuseClqAE-_1ze7BUqJHyKUrpc2b5N84wzQA";
+ static char del = 1;
+ static String USER = "james@example.com";
+ static String OAUTH_BEARER_PLAIN = ImmutableList.of("n,a=" + USER, "auth=" + BEARER, "", "")
+ .stream()
+ .collect(Collectors.joining("" + del));
Review comment:
Character.toString(char)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773599518
##########
File path: server/protocols/jwt/src/test/java/org/apache/james/jwt/OidcJwtTokenVerifierTest.java
##########
@@ -0,0 +1,136 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.HttpRequest;
+import org.mockserver.model.HttpResponse;
+
+class OidcJwtTokenVerifierTest {
+
+ private static final String JWKS_URI_PATH = "/auth/realms/realm1/protocol/openid-connect/certs";
+ private static final String JWKS_JSON = "{" +
+ " \"keys\": [" +
+ " {" +
+ " \"kid\": \"jR2tNhxU4cpRaaScaP7o2g4IFHPuKPmAhsBpuxgud6I\"," +
+ " \"kty\": \"RSA\"," +
+ " \"alg\": \"RS256\"," +
+ " \"use\": \"sig\"," +
+ " \"n\": \"Qag184iy3enJs9nnejBQAXaJRwiimE7m5qTq5SjGd6JYFFl70-uvA8S01uqnaqVHcJzkoKn14easyovz0CMp9XEJXFb7CDgYErZGDd-IK1YQTE7grD3sFn2slhR-KObakAKIXI5RGK1ICwURnV6XXWNA3ppgeS4xyycrDIH0-W0\"," +
+ " \"e\": \"AQAB\"," +
+ " \"x5c\": [" +
+ " \"MIIBlDCB/gIGAX3B+kkwMA0GCSqGSIb3DQEBCwUAMBExDzANBgNVBAMMBnJlYWxtMTAeFw0yMTEyMTYwNjQwNDVaFw0zMTEyMTYwNjQyMjVaMBExDzANBgNVBAMMBnJlYWxtMTCBnjANBgkqhkiG9w0BAQEFAAOBjAAwgYgCgYBBqDXziLLd6cmz2ed6MFABdolHCKKYTubmpOrlKMZ3olgUWXvT668DxLTW6qdqpUdwnOSgqfXh5qzKi/PQIyn1cQlcVvsIOBgStkYN34grVhBMTuCsPewWfayWFH4o5tqQAohcjlEYrUgLBRGdXpddY0DemmB5LjHLJysMgfT5bQIDAQABMA0GCSqGSIb3DQEBCwUAA4GBADCsEzJaKAnOWr0SVaneud9LYerD9Hu8GGOSASIr7zfx8C4a5VF2+np2E79Qw/18lG2ZqzgGL8fG4yrWMPvq2OFOLWuxjPaXuPGEZOCgofwla57u2oAb4jK1J/pqbnNvZjpFVKgeTwCFcCoB1gs2eAzZMo4BJewBkZtXMWG978D/\"" +
+ " ]," +
+ " \"x5t\": \"xtFhZG-qFPuLi2gSdQdhJc9cif0\"," +
+ " \"x5t#S256\": \"zJ_2j2nMcdkiYbG9qQkCVXZwHbS_iWOO5ku_nZctVE8\"" +
+ " }" +
+ " ]" +
+ "}";
+
+ private static final String PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\n" +
Review comment:
just for reserve, it will help another developer can easy to generate a valid token (for test).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005365526
## POC
Demo Video with Thunderbird
https://user-images.githubusercontent.com/81145350/148159147-a5e8687f-ed17-4ddd-85e3-d1a334e61295.mp4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769243511
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
2 options:
- We can use `com.auth0.jwk.UrlJwkProvider#getAll` method to get all publicKey, then we can try to verify token with each publicKey (loop check, not care about **kid**)
- We claim `kid` from token and get exactly PublicKey for this kid, then verify token with only ONE publicKey
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
I think to 2 options:
- We can use `com.auth0.jwk.UrlJwkProvider#getAll` method to get all publicKey, then we can try to verify token with each publicKey (loop check, not care about **kid**)
- We claim `kid` from token and get exactly PublicKey for this kid, then verify token with only ONE publicKey
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa edited a comment on pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa edited a comment on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-994791097
Sorry getting the `kid` in the token headers to only use a single key for token verification is a very good idea.
(read too quickly and did not understood despite your very good explanations @vttranlina ...)
However we should likely also handle the case when the token do not mention `kid`...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1006232348
> Empty commit, just for trigger re-run CI
Don't. Just ask a maintainer to re-launch a build.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773604536
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+ session.authenticated();
+ session.setMailboxSession(mailboxSession);
+ okComplete(request, responder);
+ } catch (AddressException e) {
+ LOGGER.error("Error encountered while login. mail address is invalid, {}", claim.get(), e);
Review comment:
I tried to embed UserRepository in here, but it needs many boilerplate, and is complex to another class that invokes AuthenticateProcessor.java.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769298093
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
Let's go with getAll as the JWT verfierr support multiple pub keys, this is the most flexible approach.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769298926
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
Review comment:
Key rotation for instance: you might keep the older key for a few days to avoid invalidating all of the tokens signed with it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-994791097
Sorry getting the `kid` in the token headers to only use a single key for token verification is a very good idea.
However we should likely also handle the case when the token do not mention `kid`...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769371267
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
Review comment:
No not really you just care about one matching cf https://github.com/apache/james-project/pull/792/commits/ded4c3056fab9ff700b70871c79a77ac63db28ba
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1004581065
Can you clean the git history? :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r770508094
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
Review comment:
> Should we have a new method in SessionProvider? (createSesison(Username userName, MailboxSession.SessionType type))
That's costly. Rene had been pushing for something similar a while ago but it ended up being non-consensual...
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773599657
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/encode/FakeImapSession.java
##########
@@ -156,6 +156,11 @@ public boolean isPlainAuthEnabled() {
return true;
}
+ @Override
+ public boolean isSupportOAuth() {
Review comment:
supportsOAuth()
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] quantranhong1999 commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
quantranhong1999 commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773576957
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtTokenHelper.java
##########
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.util.Optional;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Header;
+import io.jsonwebtoken.Jwt;
+import io.jsonwebtoken.JwtException;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.MalformedJwtException;
+
+public class JwtTokenHelper {
+
+ public static <T> Optional<T> getClaimWithoutSignatureVerification(String token, String claimName, Class<T> returnType) {
Review comment:
indent?
##########
File path: server/protocols/jwt/src/test/java/org/apache/james/jwt/OidcJwtTokenVerifierTest.java
##########
@@ -0,0 +1,136 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Optional;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.HttpRequest;
+import org.mockserver.model.HttpResponse;
+
+class OidcJwtTokenVerifierTest {
+
+ private static final String JWKS_URI_PATH = "/auth/realms/realm1/protocol/openid-connect/certs";
+ private static final String JWKS_JSON = "{" +
+ " \"keys\": [" +
+ " {" +
+ " \"kid\": \"jR2tNhxU4cpRaaScaP7o2g4IFHPuKPmAhsBpuxgud6I\"," +
+ " \"kty\": \"RSA\"," +
+ " \"alg\": \"RS256\"," +
+ " \"use\": \"sig\"," +
+ " \"n\": \"Qag184iy3enJs9nnejBQAXaJRwiimE7m5qTq5SjGd6JYFFl70-uvA8S01uqnaqVHcJzkoKn14easyovz0CMp9XEJXFb7CDgYErZGDd-IK1YQTE7grD3sFn2slhR-KObakAKIXI5RGK1ICwURnV6XXWNA3ppgeS4xyycrDIH0-W0\"," +
+ " \"e\": \"AQAB\"," +
+ " \"x5c\": [" +
+ " \"MIIBlDCB/gIGAX3B+kkwMA0GCSqGSIb3DQEBCwUAMBExDzANBgNVBAMMBnJlYWxtMTAeFw0yMTEyMTYwNjQwNDVaFw0zMTEyMTYwNjQyMjVaMBExDzANBgNVBAMMBnJlYWxtMTCBnjANBgkqhkiG9w0BAQEFAAOBjAAwgYgCgYBBqDXziLLd6cmz2ed6MFABdolHCKKYTubmpOrlKMZ3olgUWXvT668DxLTW6qdqpUdwnOSgqfXh5qzKi/PQIyn1cQlcVvsIOBgStkYN34grVhBMTuCsPewWfayWFH4o5tqQAohcjlEYrUgLBRGdXpddY0DemmB5LjHLJysMgfT5bQIDAQABMA0GCSqGSIb3DQEBCwUAA4GBADCsEzJaKAnOWr0SVaneud9LYerD9Hu8GGOSASIr7zfx8C4a5VF2+np2E79Qw/18lG2ZqzgGL8fG4yrWMPvq2OFOLWuxjPaXuPGEZOCgofwla57u2oAb4jK1J/pqbnNvZjpFVKgeTwCFcCoB1gs2eAzZMo4BJewBkZtXMWG978D/\"" +
+ " ]," +
+ " \"x5t\": \"xtFhZG-qFPuLi2gSdQdhJc9cif0\"," +
+ " \"x5t#S256\": \"zJ_2j2nMcdkiYbG9qQkCVXZwHbS_iWOO5ku_nZctVE8\"" +
+ " }" +
+ " ]" +
+ "}";
+
+ private static final String PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----\n" +
Review comment:
Q: Why we need this here?
##########
File path: server/protocols/jwt/src/test/java/org/apache/james/jwt/OidcJwksPublicKeyProviderTest.java
##########
@@ -0,0 +1,121 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.security.PublicKey;
+import java.security.interfaces.RSAPublicKey;
+import java.util.List;
+
+import org.assertj.core.api.SoftAssertions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.HttpRequest;
+import org.mockserver.model.HttpResponse;
+
+class OidcJwksPublicKeyProviderTest {
+ private static final String JWKS_URI_PATH = "/auth/realms/realm1/protocol/openid-connect/certs";
+ private static final String JWKS_JSON = "{" +
+ " \"keys\": [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IwHhcNMjExMjE0MTYxODQ3WhcNMzExMjE0MTYyMDI3WjARMQ8wDQYDVQQDDAZtYXN0ZXIwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCf190knzuyMtwcorg2KBUmTT5ue9SKal/kStl4RwmSoIOM/0jjbEHJF9hDxrQ5va/fH6dUXxwjC5wI1tESk+dadJfuwmRZ2pVChzJSkLuqBz2xPwDz31iuAiZLFDRlHgIOVxfIx8FxlNFrxrp5QF2B7lbnEfMh20QiOACizxt/ghn3gmz/J5zitXl1g5/cnnr5cHG+D1eboKELu7qHCBgf3/pHyTlbrOJh6EqCqpntiCz/XKepTmG3CjM+pyml/OnYaMcVXBsmLSalFco4HPsqMKjKY+KEL9N0sCKTY9BxlwigRrtcPzKqH6orZVTBXlRXK9IWpEmCKoR5cVIxi3ctAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAIEb/zH5YIMVL3gM/w8DnVNhFTBeZ1GUaz5uWsXmlc3aC6Lshl5lJYH27gy41bIwvQspDPsHw9h69VnN2I5aoVomJ4re94LxorxC7767mINUnwrwClhyNO1bdZWi6zeKp+pwVhBymazeXL5SV2ngBrsFZrQ7XtfhxDqRy69gFJQwJXwhD/qfhgBj+jcsYGFpvooGGLoOpc5f6gzkTv1u99NqwWSj7E4yfrcBjlrQafUdsD4nD4cSNi2Lqd7dRmCvhgIjzFOuBpEqVSgoQIwlja9Gc8hA6DVcxvZiE6q2sMzjp8Orxgl3UqqqR+Pb0ITqfM5OQLZF+nCIhryF/ZCChVM=\"" +
+ " ]," +
+ " \"x5t\": \"paqnI4t1-GuJz5PUqtTgfLjXcqw\"," +
+ " \"x5t#S256\": \"S3QfJleq8olDM3dXMb2GI2jGM_Ntdt040JOANmEGEh8\"" +
+ " }" +
+ " ]" +
+ "}";
+
+ ClientAndServer mockServer;
+
+ @BeforeEach
+ public void setUp() {
+ mockServer = ClientAndServer.startClientAndServer(0);
+ mockServer
+ .when(HttpRequest.request().withPath(JWKS_URI_PATH))
+ .respond(HttpResponse.response().withStatusCode(200)
+ .withHeader("Content-Type","application/json")
+ .withBody(JWKS_JSON, StandardCharsets.UTF_8));
+ }
+
+ private URL getJwksURL() {
+ try {
+ return new URL(String.format("http://127.0.0.1:%s%s", mockServer.getLocalPort(), JWKS_URI_PATH));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Test
+ void getShouldSuccessWhenKeyProvided() {
+ PublicKeyProvider testee = new OidcJwksPublicKeyProvider(getJwksURL(), "wu-9VZEr0gHF986PYPVzvU-5IP1q26EzzQVK_sjG29Q");
+ List<PublicKey> publicKeys = testee.get();
+ SoftAssertions.assertSoftly(softly -> {
+ softly.assertThat(publicKeys).hasSize(1);
+ softly.assertThat(publicKeys.get(0)).isInstanceOf(RSAPublicKey.class);
+ });
+ }
+
+ @Test
+ void getShouldReturnEmptyWhenKeyNotProvided() {
+ PublicKeyProvider testee = new OidcJwksPublicKeyProvider(getJwksURL(), "notfound");
+ assertThat(testee.get()).isEmpty();
+ }
+
+ @Test
+ void getShouldFailWhenBadJwksURL() throws MalformedURLException {
+ mockServer
+ .when(HttpRequest.request().withPath("/invalid"))
+ .respond(HttpResponse.response().withStatusCode(200)
+ .withBody("invalid body", StandardCharsets.UTF_8));
+
+ PublicKeyProvider testee = new OidcJwksPublicKeyProvider(new URL(String.format("http://127.0.0.1:%s/invalid", mockServer.getLocalPort())),
+ "wu-9VZEr0gHF986PYPVzvU-5IP1q26EzzQVK_sjG29Q");
Review comment:
Maybe we can reuse getJwksURL over there?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005360302
After debugging James IMAP OAuth with Thunderbird, I have some modifications to make it works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina edited a comment on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina edited a comment on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005365526
## POC
Demo Video with Thunderbird
1. Prepare for Keycloak (OIDC provider)
- Create realm
- Create app client
- Create user
2. Add Oauth Provider Server to Thunderbird
- Adding manually at thunderbird path `/thunderbird/omni.ja/OAuth2Providers.jsm`
(ref https://wiki.mozilla.org/Thunderbird:Autoconfiguration:ConfigFileFormat#OAuth2)
3. Run James IMAP server
- Config support OAuth
- Prepare test account
4. Testing
https://user-images.githubusercontent.com/81145350/148159147-a5e8687f-ed17-4ddd-85e3-d1a334e61295.mp4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1007183966
> > Empty commit, just for trigger re-run CI
>
> Don't. Just ask a maintainer to re-launch a build.
Build is green... But can you please remove that fixup now? :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa merged pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa merged pull request #796:
URL: https://github.com/apache/james-project/pull/796
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769239117
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
> As a record, Keycloack tokens might not contain kid.
From what I could see on preprod we have... However regarding the specs: https://openid.net/specs/openid-connect-core-1_0.html#Signing
```
If there are multiple keys in the referenced JWK Set document, a kid value MUST be provided in the JOSE Header.
```
If only one key is referenced, then it seems optional. But if we have more than one key it's required.
> I had problems with kid too but calling the JWKS provider with a null kid takes the first public key of the jwks URI and does the job
If for reason X or Y there is multiple keys referenced by Keycloak that's bound to be a problem no?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r770339748
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
+ session.authenticated();
+ session.setMailboxSession(mailboxSession);
+ okComplete(request, responder);
+ } catch (AddressException e) {
+ LOGGER.error("Error encountered while login. mail address is invalid, {}", claim.get(), e);
Review comment:
How can we handler "user not found" case?
Add UserRepository in this layer is will accepted?
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +163,28 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doOAuth(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Preconditions.checkArgument(session.oidcSaslConfiguration().isPresent(), "Can not do SASL when the oidcSasl configuration is not yet");
+ OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
+ Optional<String> claim = new OidcJwtTokenVerifier().verifyAndExtractClaim(jwtToken, configuration.getJwksURL(), configuration.getClaim());
+
+ if (claim.isPresent()) {
+ final MailboxManager mailboxManager = getMailboxManager();
+ try {
+ Username username = Username.fromMailAddress(new MailAddress(claim.get()));
+ MailboxSession mailboxSession = mailboxManager.createSystemSession(username);
Review comment:
Should we use `createSystemSession`?
systemSession is not the right SessionType for this case. It should be `MailboxSession.SessionType.User`
Should we have a new method in SessionProvider? (`createSesison(Username userName, MailboxSession.SessionType type)`)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769338767
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
Review comment:
thus if the kid is missing it should be failing IMO
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769492537
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
Review comment:
So you try to verify against each key then until you have a match correct? Then alright yes
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773552260
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/OidcJwtTokenVerifier.java
##########
@@ -0,0 +1,33 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.net.URL;
+import java.util.Optional;
+
+public class OidcJwtTokenVerifier {
+
+ public Optional<String> verifyAndExtractClaim(String jwtToken, URL jwksURL, String claimName) {
Review comment:
It's already in `org.apache.james.jwt.OidcJwtTokenVerifierTest`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773551428
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/api/display/HumanReadableText.java
##########
@@ -130,6 +130,7 @@ public static HumanReadableText permanentFlags(Flags flags) {
public static final HumanReadableText BAD_IO_ENCODING = new HumanReadableText("org.apache.james.imap.BAD_IO_ENCODING", "failed. Illegal encoding.");
public static final HumanReadableText COMPLETED = new HumanReadableText("org.apache.james.imap.COMPLETED", "completed.");
+ public static final HumanReadableText SUCCEEDED = new HumanReadableText("org.apache.james.imap.SUCCEEDED", "succeeded.");
Review comment:
From sample in https://datatracker.ietf.org/doc/html/rfc7628
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1007183966
> > Empty commit, just for trigger re-run CI
>
> Don't. Just ask a maintainer to re-launch a build.
Build is green... But can you please remove that fixup now? :)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa removed a comment on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa removed a comment on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005424929
`ffmpeg -i OAUTH_IMAP_JAMES.mp4 OAUTH_IMAP_JAMES_re-encoded.mp4`
https://user-images.githubusercontent.com/6928740/148172705-f66ec8a1-680a-4032-a3ca-0ebce4111237.mp4
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005644011
Rebase master & Squash fixup
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769198850
##########
File path: server/protocols/jwt/src/main/java/org/apache/james/jwt/JwtTokenHelper.java
##########
@@ -0,0 +1,50 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.jwt;
+
+import java.util.Optional;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Header;
+import io.jsonwebtoken.Jwt;
+import io.jsonwebtoken.JwtException;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.MalformedJwtException;
+
+public class JwtTokenHelper {
+
+ public static <T> Optional<T> getHeaderValueWithoutVerifySignature(String token, String claimName, Class<T> returnType) {
Review comment:
getClaimWithoutSignatureVerification
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
Review comment:
Use a `null` kid instead of failing.
##########
File path: protocols/api/src/main/java/org/apache/james/protocols/api/OidcSASLConfiguration.java
##########
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+import java.net.URL;
+
+public class OidcSASLConfiguration {
+ private final URL jwksURL;
+ private final String claim;
+ private final URL oidcConfigurationURL;
Review comment:
From my work on SASL for SMTP I do remember a `private final String scope;` field was handy...
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
I had problems with `kid` too but calling the JWKS provider with a null `kid` takes the first public key of the jwks URI and does the job.
As a record, Keycloack tokens might not contain kid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769241765
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
This is a jwks_uri response (from keycloak)
```
{
"keys": [
{
"kid": "QgjozGKW0m9NV3Gw-AdYbjyZsBd6VATHCkY8bcraewA",
"kty": "RSA",
"alg": "RS256",
"use": "enc",
"n": "jWqrqziNh5xNCXNBDIAETru3FNaqlDUAMCdcuvu8CJMm39JekugbKiPEQ7iwSEntTZ-7yVWj83nwbnc5-pVltw-6hqxY8rtCR7V0Ncfh9wqET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alFco4HPsqMKjKY+KEL9N0sCKTY9BxlwigRrtcPzKqH6orZVTBXlRXK9IWpEmCKoR5cVIxi3ctAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAIEb/zH5YIMVL3gM/w8DnVNhFTBeZ1GUaz5uWsXmlc3aC6Lshl5lJYH27gy41bIwvQspDPsHw9h69VnN2I5aoVomJ4re94LxorxC7767mINUnwrwClhyNO1bdZWi6zeKp+pwVhBymazeXL5SV2ngBrsFZrQ7XtfhxDqRy69gFJQwJXwhD/qfhgBj+jcsYGFpvooGGLoOpc5f6gzkTv1u99NqwWSj7E4yfrcBjlrQafUdsD4nD4cSNi2Lqd7dRmCvhgIjzFOuBpEqVSgoQIwlja9Gc8hA6DVcxvZiE6q2sMzjp8Orxgl3UqqqR+Pb0ITqfM5OQLZF+nCIhryF/ZCChVM="
],
"x5t": "paqnI4t1-GuJz5PUqtTgfLjXcqw",
"x5t#S256": "S3QfJleq8olDM3dXMb2GI2jGM_Ntdt040JOANmEGEh8"
}
]
}
```
We can create more publicKey if we want
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769201136
##########
File path: protocols/api/src/main/java/org/apache/james/protocols/api/OidcSASLConfiguration.java
##########
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+import java.net.URL;
+
+public class OidcSASLConfiguration {
+ private final URL jwksURL;
+ private final String claim;
+ private final URL oidcConfigurationURL;
Review comment:
Honestly, I also don't understand why we need `oidcConfigurationURL` too? Just for more information? I guess
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769199965
##########
File path: protocols/api/src/main/java/org/apache/james/protocols/api/OidcSASLConfiguration.java
##########
@@ -0,0 +1,46 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.protocols.api;
+
+import java.net.URL;
+
+public class OidcSASLConfiguration {
+ private final URL jwksURL;
+ private final String claim;
+ private final URL oidcConfigurationURL;
Review comment:
I haven't figured out what the scope's purpose is yet. Delegate?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on a change in pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r773600248
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -176,24 +175,25 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
}
private void doOAuth(String initialResponse, ImapSession session, ImapRequest request, Responder responder) {
- if (session.oidcSaslConfiguration().isEmpty()) {
+ if (!session.isSupportOAuth()) {
no(request, responder, HumanReadableText.UNSUPPORTED_AUTHENTICATION_MECHANISM);
} else {
OIDCSASLParser.parse(initialResponse)
- .flatMap(oidcInitialResponseValue -> {
- OidcSASLConfiguration configuration = session.oidcSaslConfiguration().get();
- return new OidcJwtTokenVerifier().verifyAndExtractClaim(oidcInitialResponseValue.getToken(), configuration.getJwksURL(), configuration.getClaim());
- })
+ .flatMap(oidcInitialResponseValue -> session.oidcSaslConfiguration()
+ .flatMap(configuration -> new OidcJwtTokenVerifier().verifyAndExtractClaim(oidcInitialResponseValue.getToken(), configuration.getJwksURL(), configuration.getClaim())))
.flatMap(this::extractUserFromClaim)
- .ifPresentOrElse(username -> {
- session.authenticated();
- session.setMailboxSession(getMailboxManager().createSystemSession(username));
- okSuccess(request, responder);
- }, () -> manageFailureCount(session, request, responder, HumanReadableText.AUTHENTICATION_FAILED));
+ .ifPresentOrElse(username -> doOAuthSuccess(username, session, request, responder),
+ () -> manageFailureCount(session, request, responder, HumanReadableText.AUTHENTICATION_FAILED));
}
session.stopDetectingCommandInjection();
}
+ private void doOAuthSuccess(Username username, ImapSession session, ImapRequest request, Responder responder) {
+ session.authenticated();
+ session.setMailboxSession(getMailboxManager().createSystemSession(username));
+ okComplete(request, responder);
+ }
Review comment:
Nothing related to Oauth.
Could be reused for other authentication schemes? Could be named `authSuccess` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769241765
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
This is a jwks_uri response (from keycloak)
```json
{
"keys": [
{
"kid": "LKWz5vXAObZAzwep-0HunIjkZKMavkHwtC3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Ub3NUmu7qnRSdbqOA4DiXWVwxdwBslfSTJhEvawLp1QWyx231bTEn3ou/WO++Y4WhLH8LaAUXCHpRvny2YchChkE72ndlvjK3T1dwQL0yrj7AekxS+GC77x2180IFFRHPtmA9IJ8GrfC0UeGpJDUp86jKb+rYcJOMUSQvqXMHs0iQjjm3DOEjY3Zhtwh97hIjdiy3X5+3Fotw161XXP36rO/95DAgMBAAEwDQYJKoZIhvcNAQELBQADggEBAD5+8dGYI4abh8HZrGvlaDvPI5uMX6oD7hnHzGxcWnzyR/aGZj1P4OeWHgYQ/K9jE5gAtCB52rdBLld4EUM7wA2NEV74Z8OGSasoSKXtrE+wUbbmxQlekFvVAJWZLjuzMiKfhwR7mMW+4Tq4DGsSSZoLBVx29gohtC4O9XMSO5iocq+k+mm0DSwi9RyFmjo0mChGr4KOM6wd/HCVo5DtniaHgurhguxZDmxHpA/Bf74WcctKsdUeSEPp58bZZ3qtW89G0wWnTuqeu5AgW2JMm3Can2xofd1dq1/CdLlkmOZO6/LJelPL6/UEfAXSd60Ya8qZScCmo+VpTpeTiWC2MUI="
],
"x5t": "xXOwsNLjTmoTzy6uF1lyaFx4QGw",
"x5t#S256": "wffP6FO_XinFVv5hmtXymG85jqIOtO12m5XdJmC4RU0"
}
]
}
```
We can create more publicKey if we want
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769241445
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
+ } else {
+ PublicKeyProvider publicKeyProvider = new OidcJwksPublicKeyProvider(session.oidcSaslConfiguration().get().getJwksURL(), kid.get());
+ Optional<String> verify = new JwtTokenVerifier(publicKeyProvider).verifyAndExtractLogin(jwtToken);
+
+ }
Review comment:
Keycloak token had `kid` in the jwt header. And we will use `kid` to retrieve exactly public key for verify signature.
This is a sample keycloak jwt, that I got from keycloak yesterday
```
eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJMS1d6NXZYQU9iWkF6d2VwLTBIdW5JamtaS01hdmtId3RDM1c1bDZ1aEZjIn0.eyJleHAiOjE2Mzk1MDYxNjcsImlhdCI6MTYzOTUwNTg2NywiYXV0aF90aW1lIjoxNjM5NTA1ODQxLCJqdGkiOiJjMjQ5ZTBkNi1jY2JiLTRmZDAtODI5Yi04OTM1MjczN2YzZGIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAvYXV0aC9yZWFsbXMvcmVhbG0xIiwiYXVkIjoiYWNjb3VudCIsInN1YiI6IjIwNDUyNzFiLWMxYmItNDJiOC1hMTkwLThlYWI1MmYzYmEwOSIsInR5cCI6IkJlYXJlciIsImF6cCI6ImFjY291bnQtY29uc29sZSIsIm5vbmNlIjoiNWUyOGJjNTAtODE5NS00NjM3LThmMWEtYWUzNWFlYTk0NTc1Iiwic2Vzc2lvbl9zdGF0ZSI6ImMxYzI3MmYwLWMwMjAtNGZmMC1hMzYwLTQ3MGJlYWVlNWUwMCIsImFjciI6IjAiLCJyZXNvdXJjZV9hY2Nlc3MiOnsiYWNjb3VudCI6eyJyb2xlcyI6WyJtYW5hZ2UtYWNjb3VudCIsIm1hbmFnZS1hY2NvdW50LWxpbmtzIl19fSwic2NvcGUiOiJvcGVuaWQgZW1haWwgcHJvZmlsZSIsInNpZCI6ImMxYzI3MmYwLWMwMjAtNGZmMC1hMzYwLTQ3MGJlYWVlNWUwMCIsImVtYWlsX3ZlcmlmaWVkIjpmYWxzZSwicHJlZmVycmVkX3VzZXJuYW1lIjoidHVuZyJ9.Ci7pPUViR9uEwOAqmwM-s19SKeM5gAm0qzi7B9xjv8sURmJDzns2NSAQ0aRE_YV8be0oG8qYym3iPyIKXMQx5aJ4nt7X6-eVtbAtZJK4Zs-L2OTbgmaz_j
aT8WtDTqD3I3vNd-yemx1It5z0vNQL_QuKBsWXSWfKFC3A2QysYASYRX_H8kx8Wa5-GsOMHR_xom5kZIVuweLwnCp-rCOYkbK96CmXwhPy0z6Ik16x0DMjTG_2OmJWlt32g4uT8Z3DC6EEAF4WXAQwSaPZTzDfA5HR_2_lDjlEYiFeoisJkeOZpxlZ5V52guqmmWrGynhr6sYwG5pzdYuIRLGcbbW4-w
```

--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] Arsnael commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
Arsnael commented on a change in pull request #796:
URL: https://github.com/apache/james-project/pull/796#discussion_r769239920
##########
File path: protocols/imap/src/main/java/org/apache/james/imap/processor/AuthenticateProcessor.java
##########
@@ -155,4 +165,16 @@ protected Closeable addContextToMDC(AuthenticateRequest request) {
.addToContext("authType", request.getAuthType())
.build();
}
+
+ private void doSASL(String jwtToken, ImapSession session, ImapRequest request, Responder responder) {
+ Optional<String> kid = JwtTokenHelper.getHeaderValueWithoutVerifySignature(jwtToken, "kid", String.class);
+ if (kid.isEmpty()) {
+ // fail
Review comment:
Once again what if for some reason the OIDC is referencing multiple keys?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1006231663
Empty commit, just for trigger re-run CI
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] chibenwa commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
chibenwa commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005594541
@vttranlina can you please cleanup the history?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org
[GitHub] [james-project] vttranlina commented on pull request #796: JAMES-3680 OAuth support for IMAP authentication
Posted by GitBox <gi...@apache.org>.
vttranlina commented on pull request #796:
URL: https://github.com/apache/james-project/pull/796#issuecomment-1005424094
> Can you share your exact content for this demo?
>
Yes, It's already https://issues.apache.org/jira/browse/JAMES-3680
> Also what is your version of Thunderbird?
>
- 91.4.1 (latest)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org