Skip to content

Replaced Volley calls with Graph SDK #50

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jasonjoh
Copy link

Purpose

  • Replaces raw HTTP calls via Volley with Graph SDK calls

Does this introduce a breaking change?

[ ] Yes
[ x] No

Pull Request Type

What kind of change does this Pull Request introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Documentation content changes
[ x] Other... Please describe: Enhancement

What to Check

Verify that the following are valid

  • Works like before

Other Information

This is pertinent to discussions with @baywet and @mairissi

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

@jasonjoh thanks for putting all of that together, a few minor comments from my end

}

@RequiresApi(api = Build.VERSION_CODES.N)
@Nonnull
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
@Nonnull
@Nullable

Since this method can return null

Copy link
Author

Choose a reason for hiding this comment

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

Hmm - maybe it would be better to return CompletableFuture.completedFuture(""). @baywet what would the SDK handle more gracefully?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Done

@Override
public Map<String, String> getHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("Authorization", "Bearer " + accessToken);
Copy link
Contributor

@rpdome rpdome Apr 1, 2021

Choose a reason for hiding this comment

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

The purpose of doing this is to show how exactly the token can be used to access any resources
(We picked Graph because Graph's User.Read is accessible to every accounts).

This change would encapsulate that.

I'd suggest we have an extra page (fragment) for Graph SDK, and you're free to bring in all the best practices with the Graph SDK in that one.

Copy link
Contributor

@rpdome rpdome Apr 1, 2021

Choose a reason for hiding this comment

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

If all they need to access MSGraph, and Graph SDK already wraps around the authentication part, I'd say we probably won't even need MSAL in that page

or you could have a demo of both - with, and without MSAL like what you did here

cc @hamiltonha

Copy link
Author

Choose a reason for hiding this comment

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

Graph SDK does not "do" authentication - it relies on an auth provider. It can use the provider from the Azure Identity SDK, but that SDK isn't supported in Android. So, I wrote a custom provider that wraps the token you guys already get from MSAL.

My goal here was not to undo any of the token acquisition work you've already done, just to remove the HTTP calls to Graph (which we do not want to encourage). cc @baywet

Copy link
Member

Choose a reason for hiding this comment

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

@rpdome I think there are multiple conflicting goals here:

  • Showcase how to call a custom API with native http client
  • Showcase how to call Microsoft Graph with code that is closer to real life for customers

We, as Microsoft, don't want to encourage people to call Microsoft Graph with a native client. Of course they technically can do it, but they shouldn't as they as loosing a lot of value from the different handlers to the types and the fluent APIs. Not using the SDK to call Microsoft Graph makes their applications less resilient and is not what is recommended.

Now, I understand you also want to showcase calling an API using the native HTTP client, this is fine, just pick a different API that doesn't have an SDK, or send the request to localhost with a mock.

I hope that makes sense and we can merge this PR in? We're on the identity call tomorrow and it'd be great if things were aligned.

Copy link
Contributor

@rpdome rpdome Apr 8, 2021

Choose a reason for hiding this comment

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

In that case, what about having both options in the code, but comment out the manual part?

We can explicitly call out something along the line of "If you're going to use MSGraph in your app, Please use the SDK. The manual way is kept here - in case you're trying to call other APIs"

We don't want to mock the request - because we still want the customer to 'play with the real thing' - we want to let them know that if they want to do it manually (if you don't have other options), here is how.

This sample app is supposed to be a playground after all, and MSGraph is the only SDK that are available to everyone by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants