0
votes

I have 2 API's: A and B. Both are registred in Azure AD as a API. In azure i generated a KEY to B.

Now i need generate a Access Token so i'm using ADAL Library to Java. I'm trying to use this method:

public Future<AuthenticationResult> acquireToken(final String resource,
            final UserAssertion userAssertion, final ClientCredential credential,
            final AuthenticationCallback callback)

I have the ClientCredital information but i don't have userAsstion and i don't know how generate it. Someone can help ?

This is my call:

Future<AuthenticationResult> future = context.acquireToken("http://localhost:8081",SHOULD_BE_ASSERTION,
                    new ClientCredential(CLIENT_ID,SECRET),null);
1
Do you want to call the API as a user or as the API itself? For example, if API A is called by a client with delegated permissions, then API A can use on-behalf-of to get another user token for B. If not, then you need to use another overload of acquireToken to get the token with client credentials. - juunas
I want to call API as a API not user. - Ronaldo Lanhellas

1 Answers

2
votes

It really depends what exactly OAuth flow are you trying to achieve.

The easiest in your case, and from the context of your question is Client Credentials flow (described here) without user interaction. For that flow, you need one particular overload of the AcquireToken method, namley:

Future<AuthenticationResult>    acquireToken(String resource, ClientCredential credential, AuthenticationCallback callback)

In that overload you only supply the ClientCredentials which is composed of the client_id and client_secret.

The UserAssertion is required for a different OAuth flow - on-behalf-of (described here). And this is only possible when you have end user context. This would be the Access Token for Web Api A.

Please take your time to go through the documentation and understand the different flows. Then you will also understand the libraries and SDKs.