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:40:51 UTC
[GitHub] [james-project] chibenwa commented on a change in pull request #796: [WIP] JAMES-3680 OAuth support for IMAP authentication
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