Skip to content

Rsh/azure identity auth #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 95 commits into from
Jan 22, 2021
Merged

Rsh/azure identity auth #42

merged 95 commits into from
Jan 22, 2021

Conversation

ramsessanchez
Copy link
Contributor

@ramsessanchez ramsessanchez commented Jul 31, 2020

Added TokenCredentialAuthProvider which uses Azure identity, it takes in a parameter of type TokenCredential to instantiate the class and can be used to authenticate a request by retrieving the access token. Included test classes to test this class, which required a dependency on Mockito to properly test this class.

Example:

//Create a credential of your choice, visit the Azure-Identity SDK for more info
DeviceCodeCredential deviceCodeCred = new DeviceCodeCredentialBuilder()
                .clientId(<CLIENT_ID>)
                .challengeConsumer(challenge -> {System.out.println(challenge.getMessage());})
                .build();
//Using this credential you are able to create an instance of the new TokenCredentialAuthProvider class
TokenCredentialAuthProvider tokenCredAuthProvider = new TokenCredentialAuthProvider(deviceCodeCred,< SCOPES>);
OkHttpClient httpClient = HttpClients.createDefault(tokenCredAuthProvider);
//Create an OKHTTP3 request, service library Requests should be supported on a future date
Request request = new Request.Builder().url("https://graph.microsoft.com/v1.0/me/").build();
//Call the request as you would for MSGraph: 
//https://github.com/microsoftgraph/msgraph-sdk-java#3-make-requests-against-the-service

Copied over some files from the Service library in relation to Authentication, namely the IAuthenticationProvider interface, the AuthConstants class, IHttpRequest interface, the HttpMethod enum class, and the options folder which contains the HeaderOption and Option class. All classes that were copied from the service library were placed into a folder with the same namespace as in the service library to prevent breaking changes.

Added a couple new dependencies to the the build.gradle file:
-Azure-Identity
-Mockito
-Java 8, the current LTS

Let me know if any of the javadocs included need to be clarified or simplified.

@darrelmiller
Copy link

@ramsessanchez Can you add some example code to your description that shows how you use a credential object with the SDK client?

@zengin
Copy link
Contributor

zengin commented Jan 22, 2021

Sorry for not realizing this in the first review. GitHub is not great in highlighting a binary in review.

Do we have to add gradle-wrapper.jar into source control? I have read this answer in SO: https://stackoverflow.com/a/20351077, but I am still not convinced. I am hoping this experience has improved since the time the answer was posted to SO.

And if we have to check-in, do we really need two copies of the same binary checked in?

Copy link
Contributor

@zengin zengin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Would be nice to have if we can work around not checking in the .jar files.

public void providerAddsTokenOnValidHostName() throws MalformedURLException, InterruptedException,
ExecutionException {
// Arrange
final URL url = new URL("https://graph.microsoft.com");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about a test for all of the national and public cloud endpoints (such as in the test above)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it add any value though? the code it depends on is already tested for the multiple national clouds.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, we don't need this test at all, right? Because that other test also covers https://graph.microsoft.com (unless I misunderstood)?

@baywet
Copy link
Member

baywet commented Jan 22, 2021

@zengin as far as I can tell it's standard practice to commit the wrapper jar to the repo. The script bootstraps the wrapper which in turns downloads gradle. If you remove it you need to make sure gradle is installed on the local machine, and use the globally installed version instead of the scripts.

@baywet
Copy link
Member

baywet commented Jan 22, 2021

@zengin we could update the paths in

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
We'd just need to be careful next time we update the wrapper not to overwrite it.

@baywet baywet merged commit cffa9d4 into feature/v2 Jan 22, 2021
@baywet baywet deleted the rsh/AzureIdentityAuth branch January 22, 2021 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change under-investigation Research is required and being done to decide how this issue is going to be solved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants