Skip to content

Commit

Permalink
Allow enabling broker sign-in on android
Browse files Browse the repository at this point in the history
  • Loading branch information
wslaghekke committed Sep 21, 2023
1 parent 636623c commit e683e49
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ private ISingleAccountPublicClientApplication createContextFromPluginCall(Plugin
String keyHash = call.getString("keyHash");
String authorityTypeString = call.getString("authorityType", AuthorityType.AAD.name());
String authorityUrl = call.getString("authorityUrl");
Boolean brokerRedirectUriRegistered = call.getBoolean("brokerRedirectUriRegistered", false);

if (keyHash == null || keyHash.length() == 0) {
call.reject("Invalid key hash specified.");
Expand All @@ -199,7 +200,7 @@ private ISingleAccountPublicClientApplication createContextFromPluginCall(Plugin
return null;
}

return this.createContext(clientId, domainHint, tenant, authorityType, authorityUrl, keyHash);
return this.createContext(clientId, domainHint, tenant, authorityType, authorityUrl, keyHash, brokerRedirectUriRegistered);
}

private ISingleAccountPublicClientApplication createContext(
Expand All @@ -208,20 +209,23 @@ private ISingleAccountPublicClientApplication createContext(
String tenant,
AuthorityType authorityType,
String customAuthorityUrl,
String keyHash
String keyHash,
Boolean brokerRedirectUriRegistered
) throws MsalException, InterruptedException, IOException, JSONException {
String tenantId = (tenant != null ? tenant : "common");
String authorityUrl = customAuthorityUrl != null ? customAuthorityUrl : "https://login.microsoftonline.com/" + tenantId;
String urlEncodedKeyHash = URLEncoder.encode(keyHash, "UTF-8");
String redirectUri = "msauth://" + getActivity().getApplicationContext().getPackageName() + "/" + urlEncodedKeyHash;

JSONObject configFile = new JSONObject();
JSONObject authorityConfig = new JSONObject();

switch (authorityType) {
case AAD:
authorityConfig.put("type", AuthorityType.AAD.name());
authorityConfig.put("authority_url", authorityUrl);
authorityConfig.put("audience", (new JSONObject()).put("type", "AzureADMultipleOrgs").put("tenant_id", tenantId));
configFile.put("broker_redirect_uri_registered", brokerRedirectUriRegistered);
break;
case B2C:
authorityConfig.put("type", AuthorityType.B2C.name());
Expand All @@ -230,12 +234,10 @@ private ISingleAccountPublicClientApplication createContext(
break;
}

JSONObject configFile = new JSONObject();
configFile.put("client_id", clientId);
configFile.put("domain_hint", domainHint);
configFile.put("authorization_user_agent", "DEFAULT");
configFile.put("redirect_uri", redirectUri);
configFile.put("broker_redirect_uri_registered", false);
configFile.put("account_mode", "SINGLE");
configFile.put("authorities", (new JSONArray()).put(authorityConfig));

Expand Down

0 comments on commit e683e49

Please sign in to comment.