Skip to content

Commit c4be100

Browse files
authored
Merge pull request #2592 from AzureAD/swagup/msal/valid_redirectURI
[MSAL2.x]Ensure valid broker capable redirect URI is required for AAD scenarios
2 parents f2f5007 + 1f3d15b commit c4be100

12 files changed

+216
-186
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## [TBD]
2+
* Removed deprecated APIs, including legacy initializers, account management methods, token acquisition methods, and the MSALTelemetry interface (#2577)
3+
* Enforced requirement for a valid ParentViewController (with a window) in interactive token requests (#2590)
24
* Removed deprecated methods from native auth public interface (#2588)
5+
* Removed the deprecated MSALLogger interface and implementation class (#2591)
6+
* Enforced a valid broker-capable redirect URI format for AAD scenarios (#2592)
37

48
## [1.9.0]
59
* Add feature flags provider to be controlled from broker (#2540)

MSAL/IdentityCore

Submodule IdentityCore updated 44 files

MSAL/src/MSALErrorConverter.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ + (void)initialize
5858
@(MSIDErrorServerNonHttpsRedirect) : @(MSALInternalErrorNonHttpsRedirect),
5959
@(MSIDErrorMismatchedAccount): @(MSALInternalErrorMismatchedUser),
6060
@(MSIDErrorRedirectSchemeNotRegistered): @(MSALInternalErrorRedirectSchemeNotRegistered),
61+
@(MSIDErrorInvalidRedirectURI): @(MSALInternalErrorInvalidRedirectURI),
6162

6263
// Cache
6364
@(MSIDErrorCacheMultipleUsers) : @(MSALInternalErrorAmbiguousAccount),

MSAL/src/MSALPublicClientApplication.m

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,17 @@ - (instancetype)initWithConfiguration:(MSALPublicClientApplicationConfig *)confi
185185
bypassRedirectValidation:config.bypassRedirectURIValidation
186186
error:&msidError];
187187

188-
if (!msalRedirectUri && !config.bypassRedirectURIValidation)
188+
if (!config.bypassRedirectURIValidation)
189189
{
190-
if (error) *error = [MSALErrorConverter msalErrorFromMsidError:msidError];
191-
return nil;
190+
if (!msalRedirectUri || (!msalRedirectUri.brokerCapable && config.authority.msidAuthority.supportsBrokeredAuthentication && [self isAADNonConsumerTenant:config.authority]))
191+
{
192+
if (error)
193+
{
194+
*error = [MSALErrorConverter msalErrorFromMsidError:msidError];
195+
}
196+
197+
return nil;
198+
}
192199
}
193200

194201
#if TARGET_OS_IPHONE
@@ -890,6 +897,27 @@ - (void)updateExternalAccountsWithResult:(MSALResult *)result context:(id<MSIDRe
890897
}
891898
}
892899

900+
- (BOOL)isAADNonConsumerTenant:(MSALAuthority *)authority
901+
{
902+
// Ensure the authority is of type MSALAADAuthority
903+
if (![authority isKindOfClass:[MSALAADAuthority class]]) {
904+
return NO;
905+
}
906+
907+
MSIDAuthority *msidAuthority = ((MSALAADAuthority *)authority).msidAuthority;
908+
909+
// Ensure the underlying MSID authority is of type MSIDAADAuthority
910+
if (![msidAuthority isKindOfClass:[MSIDAADAuthority class]]) {
911+
return NO;
912+
}
913+
914+
MSIDAADAuthority *aadAuthority = (MSIDAADAuthority *)msidAuthority;
915+
MSIDAADTenant *tenant = aadAuthority.tenant;
916+
917+
// Return YES if the tenant exists and is not of type 'Consumers'
918+
return (tenant != nil && tenant.type != MSIDAADTenantTypeConsumers);
919+
}
920+
893921
- (void)acquireTokenWithParameters:(MSALInteractiveTokenParameters *)parameters
894922
completionBlock:(MSALCompletionBlock)completionBlock
895923
{

MSAL/src/MSIDInteractiveRequestParameters+MSALRequest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ - (BOOL)fillWithWebViewParameters:(MSALWebviewParameters *)webParameters
5555

5656
if (parentViewController.view.window == nil)
5757
{
58-
NSError *msidError = MSIDCreateError(MSIDErrorDomain, MSIDErrorInvalidDeveloperParameter, @"parentViewController has no window! Provide a valid controller with view and window.", nil, nil, nil, nil, nil, YES);
58+
NSError *msidError = MSIDCreateError(MSIDErrorDomain, MSIDErrorInvalidDeveloperParameter, @"parentViewController has no window! Provide a valid controller with its view attached to a valid window.", nil, nil, nil, nil, nil, YES);
5959
if (error) *error = msidError;
6060
return NO;
6161
}

MSAL/src/public/MSALError.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,19 @@ typedef NS_ENUM(NSInteger, MSALInternalError)
222222
*/
223223
MSALInternalErrorRedirectSchemeNotRegistered = -42001,
224224

225+
/**
226+
The provided redirect URI is invalid.
227+
228+
Valid formats include:
229+
- Default MSAL format: "msauth.[my.app.bundleId]://auth"
230+
- ADAL format: "<custom_scheme>://[my.app.bundleId]"
231+
232+
Ensure the redirect URI matches one of the valid formats.
233+
e.g. an app with the bundle Id "com.contoso.myapp" would need redirect URI in the form: msauth.com.contoso.myapp://auth.
234+
See MSALErrorDescriptionKey for detailed error information.
235+
*/
236+
MSALInternalErrorInvalidRedirectURI = -42011,
237+
225238
/**
226239
Protocol error, such as a missing required parameter.
227240
*/

MSAL/src/public/MSALWebviewParameters.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ NS_ASSUME_NONNULL_BEGIN
4444
#pragma mark - Configuration options
4545

4646
/**
47-
The view controller to present from. This property must be valid. If nil is provided, or if the view controller is not attached to a window (i.e., parentViewController.view.window is nil), MSAL will return an error and will not proceed with authentication.
48-
It is required to provide a valid parentViewController with a window to proceed with authentication.
47+
The view controller to present from. If nil is provided, or if the view controller's view is not attached to a window (i.e., parentViewController.view.window is nil), MSAL will return an error and will not proceed with authentication.
48+
A valid parentViewController with its view attached to a valid window is required to proceed with authentication.
4949
*/
5050
@property (nonatomic, strong, nonnull) MSALViewController *parentViewController;
5151

@@ -82,9 +82,9 @@ NS_ASSUME_NONNULL_BEGIN
8282
#pragma mark - Constructing MSALWebviewParameters
8383

8484
/**
85-
Creates an instance of MSALWebviewParameters with a provided parentViewController.
86-
@param parentViewController The view controller to present authorization UI from. This property must be valid
87-
@note parentViewController is mandatory on iOS 13+ and macOS 10.15+. If nil is provided, or if the view controller is not attached to a window (i.e., parentViewController.view.window is nil), MSAL will return an error and authentication will not proceed. It is required to provide a valid parentViewController with a window to proceed with authentication.
85+
Creates an instance of MSALWebviewParameters with the provided parentViewController.
86+
@param parentViewController The view controller to present authorization UI from.
87+
@note parentViewController is mandatory on iOS 13+ and macOS 10.15+. If nil is provided, or if the view controller's view is not attached to a window (i.e., parentViewController.view.window is nil), MSAL will return an error and authentication will not proceed. A valid parentViewController with its view attached to a valid window is required to proceed with authentication.
8888
*/
8989
- (nonnull instancetype)initWithAuthPresentationViewController:(nonnull MSALViewController *)parentViewController;
9090

MSAL/src/util/MSALRedirectUri.m

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,11 @@ + (NSURL *)defaultBrokerCapableRedirectUri
6666
}
6767

6868
+ (BOOL)redirectUriIsBrokerCapable:(NSURL *)redirectUri
69+
error:(NSError * __autoreleasing *)error
6970
{
70-
return [MSIDRedirectUri redirectUriIsBrokerCapable:redirectUri] == MSIDRedirectUriValidationResultMatched;
71+
MSIDRedirectUriValidationResult validationResult = [MSIDRedirectUri redirectUriIsBrokerCapable:redirectUri
72+
error:error];
73+
return validationResult == MSIDRedirectUriValidationResultMatched;
7174
}
7275

7376
@end

0 commit comments

Comments
 (0)