Authorization Code Grant and Notifies on Microsoft Authenticator

Hi,
I want to implement this flow on my code:
- When you click on the login button, the web application (registered on Azure) makes a request to the authentication server (Azure AD) with the user's credentials (username and password).
- Azure AD verifies the user's credentials and generates a unique authorization code associated with that specific login request.
- Azure AD redirects the web application to Microsoft Authenticator, including the authorization code in the redirect.
- Microsoft Authenticator displays a notification to the user on the mobile device, requesting approval for login.
- User hits the approve button on the Microsoft Authenticator notification (within 60 seconds?)
- On the confirmation click, Microsoft Authenticator sends the authorization code to Azure AD.
- Azure AD verifies the authorization code and generates a valid access token.
- Azure AD sends the access token to the web application
Can Azure AD do these things? If yes, is this code complete?
String loginAndToken(String username, String password) throws Exception {
User user = null; PublicClientApplication application = PublicClientApplication.builder(clientID) .authority("https://login.microsoftonline.com + tenantId).build(); UserNamePasswordParameters parameters = UserNamePasswordParameters.builder(new HashSet<>(Arrays.asList("openid", "profile")), username, password.toCharArray()) .build(); IAuthenticationResult result = application.acquireToken(parameters).get(60, TimeUnit.SECONDS); if(result == null) { throw new BadCredentialsException ("User did not authorize access within 60 seconds"); } else { return result.accessToken();}
I have this problem wher I try this row:
application.acquireToken(parameters).get(60, TimeUnit.SECONDS);
This is my exception:
2023-05-15 17:15:55.173 ERROR 7708 --- [onPool-worker-1] c.m.aad.msal4j.PublicClientApplication : [Correlation ID: ########-####-####-####-############] Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed.
com.microsoft.aad.msal4j.MsalClientException: java.net.SocketTimeoutException: connect timed out
What could be the problem?
Thanks a lot