Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticated username does not match the provided #367

Open
Ingvix opened this issue Sep 15, 2024 · 1 comment
Open

Authenticated username does not match the provided #367

Ingvix opened this issue Sep 15, 2024 · 1 comment

Comments

@Ingvix
Copy link

Ingvix commented Sep 15, 2024

I trying to set up davmail for my personal mail. With davmail's own clientId I get the same notice as #363 (comment)
I then tried the Outlook Desktop clientId and redirectUri and was able proceed to sign in. After pasting the code I get this error:

java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key Authenticated username live.com#<my.email>@hotmail.com does not match <my.email>@hotmail.com
        at java.base/java.util.ResourceBundle.getObject(ResourceBundle.java:564)
        at java.base/java.util.ResourceBundle.getString(ResourceBundle.java:521)
        at davmail.BundleMessage.format(BundleMessage.java:152)
        at davmail.BundleMessage.format(BundleMessage.java:69)
        at davmail.exception.DavMailException.getMessage(DavMailException.java:59)
        at davmail.BundleMessage.getExceptionMessage(BundleMessage.java:204)
        at davmail.BundleMessage.getExceptionLogMessage(BundleMessage.java:176)
        at davmail.ui.tray.DavGatewayTray.displayMessage(DavGatewayTray.java:117)
        at davmail.ui.tray.DavGatewayTray.error(DavGatewayTray.java:194)
        at davmail.imap.ImapConnection.run(ImapConnection.java:161)

I suppose it could be due to davmail not understanding the newer API that Outlook has been updated to handle?

@ttesty
Copy link

ttesty commented Oct 6, 2024

Bug in the code... .... username = tokenBody.getString("unique_name") .. without parsing past the # in the value of "unique_name" key.

Token: {"aud":"d3590ed6-52b3-4102-aeff-aad2292ab01c","iss":"https://sts.windows.net/3ceb7ded-6237-4abf-aed0-f741fb55330a/","iat":X,"nbf":X,"exp":X,"altsecid":"1:live.com:X","amr":["pwd"],"email":"[[email protected]](mailto:[email protected])","family_name":"X","given_name":"X","idp":"live.com","idtyp":"user","ipaddr":"X","name":"X","oid":"X","puid":"X","rh":"","sub":"","tid":"X","unique_name":"live.com#[[email protected]](mailto:[email protected])","ver":"1.0","xms_idrel":"4 1"}

.... username = tokenBody.getString("unique_name");
?

You could check "email" field too... or parse on unique_name... past #

=========================
token = O365Token.build(tenantId, clientId, redirectUri, code, password);
LOGGER.debug("Authenticated username: " + token.getUsername());
if (username != null && !username.isEmpty() && !username.equalsIgnoreCase(token.getUsername())) {
throw new DavMailAuthenticationException("Authenticated username " + token.getUsername() + " does not match " + username);
}

// get username from id_token
String idToken = jsonToken.optString("id_token");
if (idToken != null && idToken.contains(".")) {
String decodedJwt = IOUtil.decodeBase64AsString(idToken.substring(idToken.indexOf("."), idToken.lastIndexOf(".")));
try {
JSONObject tokenBody = new JSONObject(decodedJwt);
LOGGER.debug("Token: " + tokenBody);
username = tokenBody.getString("unique_name");
} catch (JSONException e) {
LOGGER.warn("Invalid id_token " + e.getMessage(), e);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants