0
votes

I am trying to get authorization and access token from Azure Portal to access Microsoft Graph. I have created a simple class called PublicClient. I have also given permissions for Microsoft Graph to the Web API that I have created in Azure Portal.

My class:

public class PublicClient
{
    private static AuthenticationContext authContext = null;
    private static AuthenticationResult authResult = null;
    private static ExecutorService service = null;

    public static void main(String[] args)
    {
        try
        {
            service = Executors.newFixedThreadPool(1);
            String url = "https://login.windows.net/" +
                Authentication_Constants.TENANT + "/oauth2/token/";

            authContext = new AuthenticationContext(url, true, service);

            ClientCredential clientCred =
                new ClientCredential(Authentication_Constants.CLIENTID,
                    Authentication_Constants.SECRET);

            Future<AuthenticationResult> future =
                authContext.acquireToken(Authentication_Constants.RESOURCE,
                    clientCred, null);

            authResult = future.get();
            System.out.println(authResult.getAccessToken());
        }
        catch (Exception ex)
        {
            System.out.println(ex.getLocalizedMessage());
        }
    }
}

I am getting the following exception:

8137 [pool-1-thread-1] 
ERROR adal4jPii.class com.microsoft.aad.adal4j.AuthenticationContext - \
[Correlation ID: 946dff2f-2451-407d-8124-8a1be543bca5] Request to acquire token failed.
javax.net.ssl.SSLHandshakeException: Received fatal alert: access_denied
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)

I tried searching a lot but there is no explanation for the error.

Any suggestions? Thanks!

1
That's an SSL exception. Something is going wrong with the handshake.juunas
Which version of Java are you using? Looks like AAD supports TLS 1.0/1.1/1.2 but not SSL.juunas
@juunas Java 8.Batman22
That should support TLS just fine then. Not sure but there could be a problem with ADAL. Which version are you using?juunas
@juunas adal4 I am usingBatman22

1 Answers

0
votes

Whole issue is because of proxy and not anything related to permissions. Still make sure you are able to grant permission to the web app that you have created.But if everything is fine then all pointers points to it being a networking issue.