1

Im using adal4j to authorise a clientId/secret combination to access a shared calendar.

Heres the code I use to gain the access token.

AuthenticationContext context = null;
AuthenticationResult result = null;
ExecutorService service = null;
try {
    service = Executors.newFixedThreadPool(1);
    context = new AuthenticationContext(m_authorityUrl, false, service);

    ClientCredential creds = new ClientCredential(m_clientId, m_clientSecret);
    Future<AuthenticationResult> future = context.acquireToken(Url, creds, null);
    result = future.get();
}

In my case I am using https://login.windows.net/common/oauth2/token as the m_authorityUrl, the applicationId of the registered app for the client Id, and the secret is the one generated within the Azure portal.

However, when using the key returned (which is 1082 characters in length!), I am receiving a Http 401 code (ie not authorised). I get the key using the result.getAccessKey() function, and then add it as a header...

.addHeader("authorization", "Bearer " + m_accessKey)

Is this the correct way to use the access key, or am I accessing it wrong!?

P.S. I know that there is something wrong with the key, as if I use a token that was generated using Postman to test the call. The rest of the code works great - so the oauth token is either wrong, or the client is not authorised... Is there anyway to decipher which one? (as far as I can tell, the app is authorized in the Azure portal).

soundslikeodd
  • 1,078
  • 3
  • 19
  • 32
Morty
  • 21
  • 2

0 Answers0