Skip to content

Commit a3e168a

Browse files
author
Swasti Gupta
committed
Ensure valid broker capable redirect URI is required for AAD scenarions
1 parent 650f8ec commit a3e168a

File tree

7 files changed

+195
-43
lines changed

7 files changed

+195
-43
lines changed

MSAL/IdentityCore

Submodule IdentityCore updated 43 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: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,16 @@ - (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+
return nil;
197+
}
192198
}
193199

194200
#if TARGET_OS_IPHONE
@@ -890,6 +896,19 @@ - (void)updateExternalAccountsWithResult:(MSALResult *)result context:(id<MSIDRe
890896
}
891897
}
892898

899+
- (BOOL)isAADNonConsumerTenant:(MSALAuthority *)authority
900+
{
901+
if (![authority isKindOfClass:[MSALAADAuthority class]]) return NO;
902+
903+
MSIDAuthority *msidAuthority = ((MSALAADAuthority *)authority).msidAuthority;
904+
if (![msidAuthority isKindOfClass:[MSIDAADAuthority class]]) return NO;
905+
906+
MSIDAADAuthority *aadMsidAuthority = (MSIDAADAuthority *)msidAuthority;
907+
MSIDAADTenant *tenant = aadMsidAuthority.tenant;
908+
909+
return (tenant && tenant.type != MSIDAADTenantTypeConsumers);
910+
}
911+
893912
- (void)acquireTokenWithParameters:(MSALInteractiveTokenParameters *)parameters
894913
completionBlock:(MSALCompletionBlock)completionBlock
895914
{

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/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)