Skip to content

Commit 9726576

Browse files
authored
Merge pull request #1473 from AzureAD/sedemche/duna_cba
Support DUNA protocol for CBA flow
2 parents 694b410 + 1562cd0 commit 9726576

File tree

59 files changed

+2237
-491
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2237
-491
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 101 additions & 21 deletions
Large diffs are not rendered by default.

IdentityCore/src/MSIDConstants.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,4 +171,10 @@ typedef NS_ENUM(NSInteger, MSIDPlatformSequenceIndex)
171171
MSIDPlatformSequenceIndexLast = MSIDPlatformSequenceIndexBrowserCore,
172172
};
173173

174+
extern NSString * _Nonnull const MSID_BROWSER_RESPONSE_SWITCH_BROWSER;
175+
extern NSString * _Nonnull const MSID_BROWSER_RESPONSE_SWITCH_BROWSER_RESUME;
176+
177+
extern NSString * _Nonnull const MSID_FLIGHT_USE_V2_WEB_RESPONSE_FACTORY;
178+
extern NSString * _Nonnull const MSID_FLIGHT_SUPPORT_DUNA_CBA;
179+
174180
#define METHODANDLINE [NSString stringWithFormat:@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__]

IdentityCore/src/MSIDConstants.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,11 @@
7373

7474
NSString *const MSID_BROWSER_NATIVE_MESSAGE_ACCOUNT_ID_KEY = @"accountId";
7575

76+
NSString *const MSID_BROWSER_RESPONSE_SWITCH_BROWSER = @"switch_browser";
77+
NSString *const MSID_BROWSER_RESPONSE_SWITCH_BROWSER_RESUME = @"switch_browser_resume";
78+
79+
NSString *const MSID_FLIGHT_USE_V2_WEB_RESPONSE_FACTORY = @"use_v2_web_response_factory";
80+
NSString *const MSID_FLIGHT_SUPPORT_DUNA_CBA = @"support_duna_cba";
81+
82+
7683
#define METHODANDLINE [NSString stringWithFormat:@"%s [Line %d]", __PRETTY_FUNCTION__, __LINE__]

IdentityCore/src/webview/embeddedWebview/challangeHandlers/ios/MSIDCertAuthHandler+iOS.h renamed to IdentityCore/src/MSIDFlightManager.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//
12
// Copyright (c) Microsoft Corporation.
23
// All rights reserved.
34
//
@@ -19,29 +20,25 @@
1920
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2021
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2122
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22-
// THE SOFTWARE.
23+
// THE SOFTWARE.
24+
2325

24-
#ifndef MSIDCertAuthHandler_iOS_h
25-
#define MSIDCertAuthHandler_iOS_h
26+
#import <Foundation/Foundation.h>
2627

27-
#import "MSIDCertAuthHandler.h"
28+
NS_ASSUME_NONNULL_BEGIN
2829

29-
@interface MSIDCertAuthHandler (iOS)
30+
@protocol MSIDFlightManagerInterface <NSObject>
3031

31-
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
32+
- (BOOL)boolForKey:(NSString *)flightKey;
3233

33-
+ (void)setRedirectUriPrefix:(NSString *)prefix
34-
forScheme:(NSString *)scheme;
34+
@end
3535

36-
+ (void)setUseAuthSession:(BOOL)useAuthSession;
37-
+ (void)setUseLastRequestURL:(BOOL)useLastRequestURL;
36+
@interface MSIDFlightManager : NSObject <MSIDFlightManagerInterface>
3837

39-
// These are for cert auth challenge for iOS
40-
+ (void)setCustomActivities:(NSArray<UIActivity *> *)activities;
41-
+ (BOOL)completeCertAuthChallenge:(NSURL *)endUrl;
42-
+ (BOOL)isCertAuthInProgress;
38+
@property (nonatomic) id<MSIDFlightManagerInterface> flightProvider;
4339

44-
#endif
40+
+ (instancetype)sharedInstance;
4541

4642
@end
47-
#endif /* MSIDCertAuthHandler_mac_h */
43+
44+
NS_ASSUME_NONNULL_END
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//
2+
// Copyright (c) Microsoft Corporation.
3+
// All rights reserved.
4+
//
5+
// This code is licensed under the MIT License.
6+
//
7+
// Permission is hereby granted, free of charge, to any person obtaining a copy
8+
// of this software and associated documentation files(the "Software"), to deal
9+
// in the Software without restriction, including without limitation the rights
10+
// to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11+
// copies of the Software, and to permit persons to whom the Software is
12+
// furnished to do so, subject to the following conditions :
13+
//
14+
// The above copyright notice and this permission notice shall be included in
15+
// all copies or substantial portions of the Software.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
// THE SOFTWARE.
24+
25+
26+
#import "MSIDFlightManager.h"
27+
28+
@implementation MSIDFlightManager
29+
30+
+ (instancetype)sharedInstance
31+
{
32+
static MSIDFlightManager *sharedInstance = nil;
33+
static dispatch_once_t onceToken;
34+
dispatch_once(&onceToken, ^{
35+
sharedInstance = [[self.class alloc] init];
36+
});
37+
38+
return sharedInstance;
39+
}
40+
41+
#pragma mark - MSIDFlightManagerInterface
42+
43+
- (BOOL)boolForKey:(nonnull NSString *)flightKey
44+
{
45+
if (self.flightProvider) { return [self.flightProvider boolForKey:flightKey]; }
46+
47+
return NO;
48+
}
49+
50+
@end

IdentityCore/src/configuration/webview/MSIDAuthorizeWebRequestConfiguration.m

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ - (MSIDWebviewResponse *)responseWithResultURL:(NSURL *)url
5858
error:(NSError *__autoreleasing*)error
5959
{
6060
return [factory oAuthResponseWithURL:url
61-
requestState:self.state
62-
ignoreInvalidState:self.ignoreInvalidState
63-
context:context
64-
error:error];
61+
requestState:self.state
62+
ignoreInvalidState:self.ignoreInvalidState
63+
endRedirectUri:self.endRedirectUrl
64+
context:context
65+
error:error];
6566
}
6667

6768
@end

IdentityCore/src/oauth2/MSIDWebviewFactory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
- (MSIDWebviewResponse *)oAuthResponseWithURL:(NSURL *)url
7575
requestState:(NSString *)requestState
7676
ignoreInvalidState:(BOOL)ignoreInvalidState
77+
endRedirectUri:(NSString *)endRedirectUri
7778
context:(id<MSIDRequestContext>)context
7879
error:(NSError *__autoreleasing*)error;
7980

IdentityCore/src/oauth2/MSIDWebviewFactory.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ @implementation MSIDWebviewFactory
242242
- (MSIDWebviewResponse *)oAuthResponseWithURL:(NSURL *)url
243243
requestState:(NSString *)requestState
244244
ignoreInvalidState:(BOOL)ignoreInvalidState
245+
endRedirectUri:(NSString *)endRedirectUri
245246
context:(id<MSIDRequestContext>)context
246247
error:(NSError *__autoreleasing*)error
247248
{

IdentityCore/src/oauth2/aad_base/MSIDAADWebviewFactory.m

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#import "MSIDSignoutWebRequestConfiguration.h"
3939
#import "NSURL+MSIDAADUtils.h"
4040
#import "MSIDInteractiveTokenRequestParameters.h"
41+
#import "MSIDSwitchBrowserResponse.h"
42+
#import "MSIDSwitchBrowserResumeResponse.h"
43+
#import "MSIDFlightManager.h"
4144

4245
#if !EXCLUDE_FROM_MSALCPP
4346
#import "MSIDJITTroubleshootingResponse.h"
@@ -73,14 +76,22 @@ @implementation MSIDAADWebviewFactory
7376
{
7477
[result addEntriesFromDictionary:
7578
@{
76-
MSID_OAUTH2_CORRELATION_ID_REQUEST : @"true",
77-
MSID_OAUTH2_CORRELATION_ID_REQUEST_VALUE : [parameters.correlationId UUIDString]
78-
}];
79+
MSID_OAUTH2_CORRELATION_ID_REQUEST : @"true",
80+
MSID_OAUTH2_CORRELATION_ID_REQUEST_VALUE : [parameters.correlationId UUIDString]
81+
}];
7982
}
8083

8184
result[@"haschrome"] = @"1";
8285
[result addEntriesFromDictionary:MSIDDeviceId.deviceId];
8386

87+
#if TARGET_OS_IPHONE
88+
if ([MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA])
89+
{
90+
// Let server know that we support new cba flow
91+
result[MSID_BROWSER_RESPONSE_SWITCH_BROWSER] = @"1";
92+
}
93+
#endif
94+
8495
return result;
8596
}
8697

@@ -139,6 +150,7 @@ @implementation MSIDAADWebviewFactory
139150
- (MSIDWebviewResponse *)oAuthResponseWithURL:(NSURL *)url
140151
requestState:(NSString *)requestState
141152
ignoreInvalidState:(BOOL)ignoreInvalidState
153+
endRedirectUri:(NSString *)endRedirectUri
142154
context:(id<MSIDRequestContext>)context
143155
error:(NSError *__autoreleasing*)error
144156
{
@@ -190,7 +202,22 @@ - (MSIDWebviewResponse *)oAuthResponseWithURL:(NSURL *)url
190202
error:nil];
191203
if (browserResponse) return browserResponse;
192204

193-
// Try to create AAD Auth response
205+
if ([MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_SUPPORT_DUNA_CBA])
206+
{
207+
MSIDSwitchBrowserResponse *switchBrowserResponse = [[MSIDSwitchBrowserResponse alloc] initWithURL:url
208+
redirectUri:endRedirectUri
209+
context:context
210+
error:nil];
211+
if (switchBrowserResponse) return switchBrowserResponse;
212+
213+
MSIDSwitchBrowserResumeResponse *switchBrowserResumeResponse = [[MSIDSwitchBrowserResumeResponse alloc] initWithURL:url
214+
redirectUri:endRedirectUri
215+
context:context
216+
error:nil];
217+
if (switchBrowserResumeResponse) return switchBrowserResumeResponse;
218+
}
219+
220+
// Try to create AAD Auth response or Error response (all other reponses don't handle errors).
194221
MSIDWebAADAuthCodeResponse *response = [[MSIDWebAADAuthCodeResponse alloc] initWithURL:url
195222
requestState:requestState
196223
ignoreInvalidState:ignoreInvalidState

0 commit comments

Comments
 (0)