Skip to content

MSALRuntime integration#530

Closed
Avery-Dunn wants to merge 4 commits intodevfrom
avdunn/msalruntime-integration
Closed

MSALRuntime integration#530
Avery-Dunn wants to merge 4 commits intodevfrom
avdunn/msalruntime-integration

Conversation

@Avery-Dunn
Copy link
Contributor

@Avery-Dunn Avery-Dunn commented Aug 31, 2022

Draft PR for the work-in-progress MSALRuntime integration. Most of the new files will be split off into either a new Broker repository or the existing MSAL C++ repository, and are just here for easier initial code review

This PR currently has:

  • IBroker.java an interface used to reference methods implemented by a broker package, such as our upcoming WAMBroker that allows using WAM via MSALRuntime
  • Changes in some existing flows to demonstrate the use of IBroker
  • MSALRuntimeLibrary.java, which will be used to make the actual calls to the MSALRuntime API and will be placed in the MSAL C++ repo (where it will be known as the 'interop layer', and the PR for it is: https://github.com/AzureAD/microsoft-authentication-library-for-cpp/pull/3091)

/**
* Used to define the basic set of methods that all Brokers must implement
*/
public interface IBroker {

Choose a reason for hiding this comment

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

The I prefix is quite an outdated approach. I would suggest you consider calling this Broker instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed that it is an outdated approach but we try to be in sync with other MSALs. This IBroker interface is introduced to be in sync with MSAL .NET.

Choose a reason for hiding this comment

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

I would argue to not follow conventions of another language, if you can help it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also agree that it's outdated, but it's also something that all the other interfaces in our library follow. Consistency with the other MSALs is also a big focus for this feature, since most of the libraries will be also be integrating with MSALRuntime we want to keep things as similar as we can

Comment on lines +9 to +20
Account signInSilently(PublicClientApplication clientApplication, InteractiveRequestParameters interactiveRequestParameters);

Account signInInteractively(PublicClientApplication clientApplication, InteractiveRequestParameters interactiveRequestParameters);

AuthenticationResult acquireTokenSilently(PublicClientApplication clientApplication, InteractiveRequestParameters interactiveRequestParameters, Account account);

AuthenticationResult acquireTokenInteractively(PublicClientApplication clientApplication, InteractiveRequestParameters interactiveRequestParameters, Account account);

void signOutSilently(PublicClientApplication clientApplication, InteractiveRequestParameters interactiveRequestParameters);

//TODO: too specific to MSALRuntime? Should it be split into a generic getAccount(something) and getAllAccounts(clientId)?
void discoverAccounts(PublicClientApplication clientApplication, InteractiveRequestParameters interactiveRequestParameters);

Choose a reason for hiding this comment

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

Because all methods seem to require a PublicClientApplication, I wonder if this should be a constructor parameter in implementations of this interface? Do you expect for an instance of Broker that the PublicClientApplication will always be the same?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been completely refactored from this initial generic design to something more like the rest of MSAL Java, where there are a series of acquireToken() methods overloaded for each type of request (leaving it up to a broker to figure out how to handle each type of request).

AuthorizationResult authorizationResult = getAuthorizationResult();
validateState(authorizationResult);
return acquireTokenWithAuthorizationCode(authorizationResult);
if (clientApplication.allowBroker()) {

Choose a reason for hiding this comment

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

We should have boolean getters prefixed with is, so perhaps this method should be named isBrokerAllowed() or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just the flag decided on in the design doc (mainly according to conventions in Python and .NET since they were the frontrunners on this). Normally I'd agree that it's weird and change it to something like 'isBrokerAllowed', but consistency across MSALs is a focus on this project, and we other parameters like this in our library already so it shouldn't be too confusing.

Comment on lines +13 to +20
public LongByReference authParamsHandle;
public LongByReference accountHandle;
public LongByReference authResultHandle;
public MSALRuntimeUtils.StringByReference idToken = new MSALRuntimeUtils.StringByReference(new WString(""));
public MSALRuntimeUtils.StringByReference accessToken = new MSALRuntimeUtils.StringByReference(new WString(""));
public LongByReference accessTokenExpirationTime;
public MSALRuntimeUtils.StringByReference accountId = new MSALRuntimeUtils.StringByReference(new WString(""));//TODO: split AuthenticationResult into SignInResult (id token/account) and TokenResult (access tokens)? Or keep it simple all-in-one like MSAL Java's AuthenticationResult?
public MSALRuntimeUtils.StringByReference accountClientInfo = new MSALRuntimeUtils.StringByReference(new WString(""));

Choose a reason for hiding this comment

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

We shouldn't have public instance fields in our APIs, if at all possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These fields (and the class itself) need to be public due to how JNA handles converting Java classes to C structs. Basically, JNA will ignore any field that isn't public when creating the native struct, so anything on the Java side tried to access native structs JNA is handling you'd get an error about the struct not having a field named XYZ.

@Avery-Dunn
Copy link
Contributor Author

Enough design changes have happened to make this version obsolete, new PR IBroker and it's implementation for MSALRuntime can be found here: #563

@Avery-Dunn Avery-Dunn closed this Oct 23, 2022
@Avery-Dunn Avery-Dunn deleted the avdunn/msalruntime-integration branch January 31, 2023 22:11
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.

3 participants