Skip to content

Commit 0914917

Browse files
authored
Add support for broker on MacOS (Azure#50999)
1 parent ea4d549 commit 0914917

File tree

11 files changed

+90
-13
lines changed

11 files changed

+90
-13
lines changed

eng/Packages.Data.props

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@
177177
<!-- Other approved packages -->
178178
<PackageReference Update="Microsoft.Azure.Amqp" Version="2.7.0" />
179179
<PackageReference Update="Microsoft.Azure.WebPubSub.Common" Version="1.4.0" />
180-
<PackageReference Update="Microsoft.Identity.Client" Version="4.71.1" />
181-
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="4.71.1" />
182-
<PackageReference Update="Microsoft.Identity.Client.Broker" Version="4.71.1" />
180+
<PackageReference Update="Microsoft.Identity.Client" Version="4.73.1" />
181+
<PackageReference Update="Microsoft.Identity.Client.Extensions.Msal" Version="4.73.1" />
182+
<PackageReference Update="Microsoft.Identity.Client.Broker" Version="4.73.1" />
183183
<PackageReference Update="Microsoft.IdentityModel.Protocols.OpenIdConnect" Version="6.35.0" />
184184
<PackageReference Update="Microsoft.IdentityModel.Tokens" Version="6.35.0" />
185185
<PackageReference Update="System.IdentityModel.Tokens.Jwt" Version="6.35.0" />

sdk/identity/Azure.Identity.Broker/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### Features Added
66

7+
- Support Microsoft Broker on macOS.
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/identity/Azure.Identity.Broker/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ Microsoft accounts (MSA) are personal accounts created by users to access Micros
3434

3535
## Redirect URIs
3636

37-
Microsoft Entra applications rely on redirect URIs to determine where to send the authentication response after a user has logged in. To enable brokered authentication through WAM, a redirect URI matching the following pattern should be registered to the application:
38-
39-
```
40-
ms-appx-web://Microsoft.AAD.BrokerPlugin/{client_id}
41-
```
37+
Microsoft Entra applications rely on redirect URIs to determine where to send the authentication response after a user has logged in. To enable brokered authentication, a redirect URI matching the following pattern should be registered to the application:
38+
39+
| Platform | Redirect URI |
40+
|-------------|-----------------------------------------------------------------------------------------------------------------------|
41+
| Windows 10+ | `ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id` |
42+
| macOS | `msauth.com.msauth.unsignedapp://auth` for unsigned applications<br>`msauth.BUNDLE_ID://auth` for signed applications |
43+
| WSL | `ms-appx-web://Microsoft.AAD.BrokerPlugin/your_client_id` |
44+
| Linux | `https://login.microsoftonline.com/common/oauth2/nativeclient` |
4245

4346
## Examples
4447

sdk/identity/Azure.Identity.Broker/src/DevelopmentBrokerOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics.CodeAnalysis;
6+
using System.Runtime.InteropServices;
67
using Microsoft.Identity.Client;
78
using Microsoft.Identity.Client.Broker;
89

@@ -31,6 +32,12 @@ internal class DevelopmentBrokerOptions : InteractiveBrowserCredentialOptions, I
3132
public DevelopmentBrokerOptions() : base()
3233
{
3334
_beforeBuildClient = AddBroker;
35+
36+
// Set default value for UseDefaultBrokerAccount on macOS
37+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
38+
{
39+
RedirectUri = new(Constants.MacBrokerRedirectUri);
40+
}
3441
}
3542

3643
Action<PublicClientApplicationBuilder> IMsalSettablePublicClientInitializerOptions.BeforeBuildClient
@@ -44,7 +51,7 @@ Action<PublicClientApplicationBuilder> IMsalSettablePublicClientInitializerOptio
4451
private void AddBroker(PublicClientApplicationBuilder builder)
4552
{
4653
builder.WithParentActivityOrWindow(() => IntPtr.Zero);
47-
var options = new BrokerOptions(BrokerOptions.OperatingSystems.Windows | BrokerOptions.OperatingSystems.Linux);
54+
var options = new BrokerOptions(BrokerOptions.OperatingSystems.Windows | BrokerOptions.OperatingSystems.Linux | BrokerOptions.OperatingSystems.OSX);
4855
if (IsLegacyMsaPassthroughEnabled.HasValue)
4956
{
5057
options.MsaPassthrough = IsLegacyMsaPassthroughEnabled.Value;

sdk/identity/Azure.Identity.Broker/src/InteractiveBrowserCredentialBrokerOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Runtime.InteropServices;
56
using Microsoft.Identity.Client;
67
using Microsoft.Identity.Client.Broker;
78

@@ -32,14 +33,20 @@ public class InteractiveBrowserCredentialBrokerOptions : InteractiveBrowserCrede
3233
public InteractiveBrowserCredentialBrokerOptions(IntPtr parentWindowHandle) : base()
3334
{
3435
_parentWindowHandle = parentWindowHandle;
36+
37+
// Set default value for UseDefaultBrokerAccount on macOS
38+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
39+
{
40+
RedirectUri = new(Constants.MacBrokerRedirectUri);
41+
}
3542
}
3643

3744
Action<PublicClientApplicationBuilder> IMsalPublicClientInitializerOptions.BeforeBuildClient => AddBroker;
3845

3946
private void AddBroker(PublicClientApplicationBuilder builder)
4047
{
4148
builder.WithParentActivityOrWindow(() => _parentWindowHandle);
42-
var options = new BrokerOptions(BrokerOptions.OperatingSystems.Windows | BrokerOptions.OperatingSystems.Linux);
49+
var options = new BrokerOptions(BrokerOptions.OperatingSystems.Windows | BrokerOptions.OperatingSystems.Linux | BrokerOptions.OperatingSystems.OSX);
4350
if (IsLegacyMsaPassthroughEnabled.HasValue)
4451
{
4552
options.MsaPassthrough = IsLegacyMsaPassthroughEnabled.Value;

sdk/identity/Azure.Identity/TROUBLESHOOTING.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ This troubleshooting guide covers failure investigation techniques, common error
2424
- [Troubleshoot AzureCliCredential authentication issues](#troubleshoot-azureclicredential-authentication-issues)
2525
- [Troubleshoot AzurePowerShellCredential authentication issues](#troubleshoot-azurepowershellcredential-authentication-issues)
2626
- [Troubleshoot multi-tenant authentication issues](#troubleshoot-multi-tenant-authentication-issues)
27-
- [Troubleshoot Web Account Manager (WAM) brokered authentication issues](#troubleshoot-web-account-manager-wam-brokered-authentication-issues)
27+
- [Troubleshoot brokered authentication issues](#troubleshoot-brokered-authentication-issues)
2828
- [Troubleshoot AzurePipelinesCredential authentication issues](#troubleshoot-azurepipelinescredential-authentication-issues)
2929
- [Get additional help](#get-additional-help)
3030

@@ -335,8 +335,9 @@ Get-AzAccessToken -ResourceUrl "https://management.core.windows.net"
335335
|---|---|---|
336336
|The current credential is not configured to acquire tokens for tenant <tenant ID>|<p>The application must configure the credential to allow token acquisition from the requested tenant.|Make one of the following changes in your app:<ul><li>Add the requested tenant ID to `AdditionallyAllowedTenants` on the credential options.</li><li>Add `*` to `AdditionallyAllowedTenants` to allow token acquisition for any tenant.</li></ul></p><p>This exception was added as part of a breaking change to multi-tenant authentication in version `1.7.0`. Users experiencing this error after upgrading can find details on the change and migration in [BREAKING_CHANGES.md](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/BREAKING_CHANGES.md#170).</p> |
337337

338-
## Troubleshoot Web Account Manager (WAM) brokered authentication issues
338+
## Troubleshoot brokered authentication issues
339339

340+
### Common error messages for Web Account Manager (WAM)
340341
| Error Message |Description| Mitigation |
341342
|---|---|---|
342343
|AADSTS50011|The application is missing the expected redirect URI.|Ensure that one of redirect URIs registered for the Microsoft Entra application matches the following URI pattern: `ms-appx-web://Microsoft.AAD.BrokerPlugin/{client_id}`|
@@ -359,6 +360,12 @@ You may also log in another MSA account by selecting "Microsoft account":
359360

360361
![Microsoft account](./images/MSA4.png)
361362

363+
### Common errors for broker on macOS
364+
365+
| Error Message |Description| Mitigation |
366+
|---|---|---|
367+
|0xffffffffffff5bf0 - Application's teamId is missing, and redirectUri is not matching unsigned format|For console applications using the broker on macOS, the following `RedirectUri` should be set: `msauth.com.msauth.unsignedapp://auth`|
368+
362369
## Troubleshoot AzurePipelinesCredential authentication issues
363370

364371
| Error Message | Description | Mitigation |

sdk/identity/Azure.Identity/src/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,6 @@ internal class Constants
5353
public const string ManagedIdentityCredential = "managedidentitycredential";
5454
public const string InteractiveBrowserCredential = "interactivebrowsercredential";
5555
public const string BrokerAuthenticationCredential = "brokerauthenticationcredential";
56+
public const string MacBrokerRedirectUri = "msauth.com.msauth.unsignedapp://auth";
5657
}
5758
}

sdk/identity/Azure.Identity/src/Credentials/DevelopmentBrokerOptions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using Microsoft.Identity.Client;
67

78
namespace Azure.Identity
@@ -37,5 +38,17 @@ Action<PublicClientApplicationBuilder> IMsalSettablePublicClientInitializerOptio
3738
}
3839

3940
Action<PublicClientApplicationBuilder> IMsalPublicClientInitializerOptions.BeforeBuildClient => _beforeBuildClient;
41+
42+
internal override T Clone<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>()
43+
{
44+
var clone = base.Clone<T>();
45+
46+
if (clone is DevelopmentBrokerOptions dboClone)
47+
{
48+
dboClone.IsLegacyMsaPassthroughEnabled = IsLegacyMsaPassthroughEnabled;
49+
dboClone.UseDefaultBrokerAccount = UseDefaultBrokerAccount;
50+
}
51+
return clone;
52+
}
4053
}
4154
}

sdk/identity/Azure.Identity/src/Credentials/InteractiveBrowserCredentialOptions.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Threading;
78
using Microsoft.Identity.Client;
89

@@ -71,5 +72,32 @@ public string TenantId
7172
/// The options for customizing the browser for interactive authentication.
7273
/// </summary>
7374
public BrowserCustomizationOptions BrowserCustomization { get; set; }
75+
76+
internal override T Clone<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.NonPublicConstructors)] T>()
77+
{
78+
var clone = base.Clone<T>();
79+
if (clone is InteractiveBrowserCredentialOptions ibcoClone)
80+
{
81+
ibcoClone.DisableAutomaticAuthentication = DisableAutomaticAuthentication;
82+
ibcoClone.TenantId = _tenantId;
83+
ibcoClone.AdditionallyAllowedTenants = AdditionallyAllowedTenants;
84+
ibcoClone.ClientId = ClientId;
85+
ibcoClone.TokenCachePersistenceOptions = TokenCachePersistenceOptions?.Clone();
86+
ibcoClone.RedirectUri = RedirectUri;
87+
ibcoClone.AuthenticationRecord = AuthenticationRecord;
88+
ibcoClone.LoginHint = LoginHint;
89+
ibcoClone.DisableInstanceDiscovery = DisableInstanceDiscovery;
90+
if (BrowserCustomization != null)
91+
{
92+
ibcoClone.BrowserCustomization = new BrowserCustomizationOptions
93+
{
94+
ErrorMessage = BrowserCustomization.ErrorMessage,
95+
SuccessMessage = BrowserCustomization.SuccessMessage,
96+
UseEmbeddedWebView = BrowserCustomization.UseEmbeddedWebView ?? false
97+
};
98+
}
99+
}
100+
return clone;
101+
}
74102
}
75103
}

sdk/identity/Azure.Identity/src/DefaultAzureCredentialFactory.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Reflection;
7+
using System.Runtime.InteropServices;
78
using Azure.Core;
89

910
namespace Azure.Identity
@@ -240,6 +241,7 @@ public TokenCredential CreateBrokerAuthenticationCredential(InteractiveBrowserCr
240241
{
241242
var options = Options.Clone<DevelopmentBrokerOptions>();
242243
((IMsalSettablePublicClientInitializerOptions)options).BeforeBuildClient = ((IMsalSettablePublicClientInitializerOptions)brokerOptions).BeforeBuildClient;
244+
options.RedirectUri = brokerOptions.RedirectUri;
243245

244246
options.TokenCachePersistenceOptions = new TokenCachePersistenceOptions();
245247

@@ -322,6 +324,12 @@ internal static bool TryCreateDevelopmentBrokerOptions(out InteractiveBrowserCre
322324
ConstructorInfo optionsCtor = optionsType?.GetConstructor(Type.EmptyTypes);
323325
object optionsInstance = optionsCtor?.Invoke(null);
324326
options = optionsInstance as InteractiveBrowserCredentialOptions;
327+
options.IsChainedCredential = true;
328+
// Set default value for UseDefaultBrokerAccount on macOS
329+
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
330+
{
331+
options.RedirectUri = new(Constants.MacBrokerRedirectUri);
332+
}
325333

326334
return options != null;
327335
}

0 commit comments

Comments
 (0)