Open NCarrellOmni opened 2 weeks ago
~Don't set a customAuthenticator. If you leave it unset it will use a default Microsoft oauth2 authenticator. You can specify the authenticationEndpoint using MicrosoftClientBuilder if you like otherwise it will use AuthenticationEndpoint.GLOBAL
.~
Oops, you are using on-premise. So auth is working or not? Using the URL parameter is optional. I see in MicrosoftClientBuilder a comment on this:
authenticator((url, requestHeaders) -> {
// some streaming endpoints object to auth so don't add header
// if not on the base service
if (url.toExternalForm().startsWith(b.baseUrl)) {
// remove Authorization header if present
List<RequestHeader> list = requestHeaders //
.stream() //
.filter(rh -> !rh.name().equalsIgnoreCase("Authorization")) //
.collect(Collectors.toList());
// add basic auth request header
UsernamePassword c = bc.get();
list.add(basicAuth(c.username(), c.password()));
return list;
} else {
return requestHeaders;
}
});
Anyway your approach looks good and is what other Dynamics builders look like too, like this finance one.
BTW, I would normally use an auto-refreshing token retrieval approach so you only need one instance of the built client
. The class ClientCredentialsAccessTokenProvider might be useful.
You could adapt this from MicrosoftClientBuilder for refreshing tokens. We can discuss making MicrosoftClientBuilder a bit more flexible for on-premise too, we'll see what you find.
Thank you for the information.
We will look at ClientCredentialsAccessTokenProvider
and MicrosoftClientBuilder
and see what we can come up with for refreshing tokens.
Refactoring ClientCredentialsAccessTokenProvider and MicrosoftClientBuilder now to make it easier for on-prem.
Here's an on-prem support PR for you to review if you like. I'll merge it soon if no response and build a new release.
I looked over the code and this looks good.
I've pulled down the on-prem branch so we can get started. I will open another issue if we run into any more problems. Thank you again for the info and help.
0.2.1 is on Maven Central now with on-prem support.
My team is building an Android application to interface with Dynamics 365 CRM On-Premise and we will be using OAuth. I read through the odata-client-microsoft-client-builder source to try and piece something together. Are there any recommendations for implementing OAuth with Dynamics 365?
I did the following and found that my implementation does work, but I'm not confident that this is the 'correct' way to use
BuilderCustomAuthenticator
or theAuthenticator
interface.I copied the example from com.github.davidmoten.ms.dynamics.Dynamics and made these changes:
tenantName
basicAuthentication
methods withBuilderCustomAuthenticator<T> customAuthenticator(Authenticator authenticator)
Then I created my custom
Authenticator
by implementing theAuthenticator
interface. I ended up not using the URL parameter. Should I be using this parameter? If so, what for?Finally, I instantiate my client. The getAuthToken() method uses the username/password to retrieve an authorization token from ADFS and returns that token as a String.