use of com.microsoft.aad.msal4j.IntegratedWindowsAuthenticationParameters in project microsoft-authentication-library-for-java by AzureAD.
the class IntegratedWindowsAuthenticationFlow method acquireTokenIntegratedWindowsAuth.
private static IAuthenticationResult acquireTokenIntegratedWindowsAuth(PublicClientApplication pca, Set<String> scope, IAccount account, String username) throws Exception {
IAuthenticationResult result;
try {
SilentParameters silentParameters = SilentParameters.builder(scope).account(account).build();
// Try to acquire token silently. This will fail on the first acquireTokenIntegratedWindowsAuth() call
// because the token cache does not have any data for the user you are trying to acquire a token for
result = pca.acquireTokenSilently(silentParameters).join();
System.out.println("==acquireTokenSilently call succeeded");
} catch (Exception ex) {
if (ex.getCause() instanceof MsalException) {
System.out.println("==acquireTokenSilently call failed: " + ex.getCause());
IntegratedWindowsAuthenticationParameters parameters = IntegratedWindowsAuthenticationParameters.builder(scope, username).build();
// Try to acquire a token using Integrated Windows Authentication (IWA). You will need to generate a Kerberos ticket.
// If successful, you should see the token and account information printed out to console
result = pca.acquireToken(parameters).join();
System.out.println("==Integrated Windows Authentication flow succeeded");
} else {
// Handle other exceptions accordingly
throw ex;
}
}
return result;
}
Aggregations