Microsoft Graph App授权Java独立应用程序

时间:2018-02-09 17:22:19

标签: java azure-active-directory microsoft-graph

我正在尝试从Azure门户获取授权和访问令牌以访问Microsoft Graph。我创建了一个名为PublicClient的简单类。我还将Microsoft Graph的权限授予我在Azure门户中创建的Web API。

我的课程:

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());
        }
    }
}

我收到以下异常:

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)

我试了很多,但没有解释错误。

有什么建议吗?谢谢!

1 个答案:

答案 0 :(得分:0)

整个问题是因为代理而不是与权限相关的任何内容。仍然要确保您能够授予您创建的Web应用程序的权限。但如果一切正常,那么所有指针都指向它是一个网络问题。