Skip to content

Commit ebefa86

Browse files
authored
Merge pull request #1534 from AzureAD/josephpab/dunaBitMask
Added ephemeral browser session to duna
2 parents f3b83fe + 193dd91 commit ebefa86

File tree

9 files changed

+50
-5
lines changed

9 files changed

+50
-5
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5098,7 +5098,6 @@
50985098
B2AF1D29218BCDEF0080C1A0 /* requests */ = {
50995099
isa = PBXGroup;
51005100
children = (
5101-
51025101
720B5B542DD57D6600318FE5 /* MSIDEcdhApv.m */,
51035102
720B5B522DD57C3700318FE5 /* MSIDEcdhApv.h */,
51045103
720B5B4F2DD577C100318FE5 /* MSIDJWECrypto.m */,

IdentityCore/src/webview/MSIDCertAuthManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
4444
- (void)startWithURL:(NSURL *)startURL
4545
parentController:(MSIDViewController *)parentViewController
4646
context:(id<MSIDRequestContext>)context
47+
ephemeralWebBrowserSession:(BOOL)ephemeralWebBrowserSession
4748
completionBlock:(MSIDWebUICompletionHandler)completionBlock;
4849

4950
- (BOOL)completeWithCallbackURL:(NSURL *)url;

IdentityCore/src/webview/MSIDCertAuthManager.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ - (BOOL)completeWithCallbackURL:(NSURL *)url
7979
- (void)startWithURL:(NSURL *)startURL
8080
parentController:(MSIDViewController *)parentViewController
8181
context:(id<MSIDRequestContext>)context
82+
ephemeralWebBrowserSession:(BOOL)ephemeralWebBrowserSession
8283
completionBlock:(MSIDWebUICompletionHandler)completionBlock
8384
{
8485
[MSIDMainThreadUtil executeOnMainThreadIfNeeded:^{
@@ -113,7 +114,7 @@ - (void)startWithURL:(NSURL *)startURL
113114
parentController:parentViewController
114115
useAuthenticationSession:self.useAuthSession
115116
allowSafariViewController:YES
116-
ephemeralWebBrowserSession:YES
117+
ephemeralWebBrowserSession:ephemeralWebBrowserSession
117118
context:context];
118119

119120
self.systemWebViewController.appActivities = self.activities;

IdentityCore/src/webview/embeddedWebview/challangeHandlers/ios/MSIDCertAuthHandler.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ + (BOOL)handleChallenge:(NSURLAuthenticationChallenge *)challenge
9696
[MSIDCertAuthManager.sharedInstance startWithURL:requestURL
9797
parentController:parentViewController
9898
context:context
99+
ephemeralWebBrowserSession:YES
99100
completionBlock:^(NSURL *callbackURL, NSError *error)
100101
{
101102
MSIDWebviewSession *session = [MSIDWebviewAuthorization currentSession];

IdentityCore/src/webview/operations/ios/MSIDSwitchBrowserOperation.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2323
// THE SOFTWARE.
2424

25-
2625
#import "MSIDSwitchBrowserOperation.h"
2726
#import "MSIDSystemWebviewController.h"
2827
#import "MSIDWebviewResponse.h"
@@ -90,6 +89,7 @@ - (void)invokeWithRequestParameters:(nonnull MSIDInteractiveTokenRequestParamete
9089
[self.certAuthManager startWithURL:startURL
9190
parentController:requestParameters.parentViewController
9291
context:requestParameters
92+
ephemeralWebBrowserSession:self.switchBrowserResponse.useEphemeralWebBrowserSession
9393
completionBlock:^(NSURL *callbackURL, NSError *error)
9494
{
9595
[self.certAuthManager resetState];

IdentityCore/src/webview/response/MSIDSwitchBrowserResponse.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@
2727

2828
@interface MSIDSwitchBrowserResponse : MSIDWebviewResponse
2929

30+
typedef NS_OPTIONS(NSInteger, MSIDSwitchBrowserModes) {
31+
BrowserModePrivateSession = 1 << 0,
32+
// Add future flags here
33+
};
34+
3035
@property (nonatomic, readonly) NSString *actionUri;
3136
@property (nonatomic, readonly) NSString *switchBrowserSessionToken;
37+
@property (nonatomic, readonly) BOOL useEphemeralWebBrowserSession;
3238

3339
- (instancetype )init NS_UNAVAILABLE;
3440
+ (instancetype)new NS_UNAVAILABLE;

IdentityCore/src/webview/response/MSIDSwitchBrowserResponse.m

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#import "MSIDWebResponseOperationFactory.h"
2828
#import "MSIDConstants.h"
2929
#import "MSIDFlightManager.h"
30+
#import "NSData+MSIDExtensions.h"
3031

3132
@implementation MSIDSwitchBrowserResponse
3233

@@ -47,8 +48,20 @@ - (instancetype)initWithURL:(NSURL *)url
4748
if (self)
4849
{
4950
if (![self isMyUrl:url redirectUri:redirectUri]) return nil;
50-
5151
_actionUri = self.parameters[@"action_uri"];
52+
_useEphemeralWebBrowserSession = YES;
53+
54+
NSString* browserOptionsString = self.parameters[@"browser_modes"];
55+
if (browserOptionsString)
56+
{
57+
NSData *data = [NSData msidDataFromBase64UrlEncodedString:browserOptionsString];
58+
uint32_t flagsValue = 0;
59+
[data getBytes:&flagsValue length:sizeof(flagsValue)];
60+
61+
MSIDSwitchBrowserModes modes = (MSIDSwitchBrowserModes)flagsValue;
62+
_useEphemeralWebBrowserSession = modes & BrowserModePrivateSession;
63+
}
64+
5265
if ([NSString msidIsStringNilOrBlank:_actionUri])
5366
{
5467
if (error) *error = MSIDCreateError(MSIDOAuthErrorDomain, MSIDErrorServerInvalidResponse, @"action_uri is nil.", nil, nil, nil, context.correlationId, nil, YES);
@@ -123,5 +136,4 @@ - (BOOL)isMyUrl:(NSURL *)url
123136
return [self.class isDUNAActionUrl:url operation:[self.class operation]];
124137
}
125138

126-
127139
@end

IdentityCore/tests/MSIDSwitchBrowserOperationTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class MSIDCertAuthManagerMock: MSIDCertAuthManager
3434
override func start(with startURL: URL,
3535
parentController parentViewController: UIViewController,
3636
context: any MSIDRequestContext,
37+
ephemeralWebBrowserSession: Bool,
3738
completionBlock: @escaping MSIDWebUICompletionHandler)
3839
{
3940
startWithUrlInvokedCount += 1

IdentityCore/tests/MSIDSwitchBrowserResponseTest.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ final class MSIDSwitchBrowserResponseTest: XCTestCase
8282
XCTAssertEqual(response?.switchBrowserSessionToken, "some_code")
8383
}
8484

85+
func testInit_whenValidBrowserMode_hasBitmaskPrivateSessionShouldBeTrue() throws
86+
{
87+
let url = URL(string: "msauth://broker_bundle_id//switch_browser?action_uri=some_uri&code=some_code&browser_modes=AQAAAA")!
88+
89+
let response = try? MSIDSwitchBrowserResponse(url: url, redirectUri: "msauth://broker_bundle_id", context: nil)
90+
91+
XCTAssertNotNil(response)
92+
XCTAssertEqual(response?.actionUri, "some_uri")
93+
XCTAssertEqual(response?.switchBrowserSessionToken, "some_code")
94+
XCTAssertEqual(response?.useEphemeralWebBrowserSession, true)
95+
}
96+
97+
func testInit_whenInvalidBrowserMode_hasBitmaskPrivateSessionShouldBeFalse() throws
98+
{
99+
let url = URL(string: "msauth://broker_bundle_id//switch_browser?action_uri=some_uri&code=some_code&browser_modes=AAAAAA")!
100+
101+
let response = try? MSIDSwitchBrowserResponse(url: url, redirectUri: "msauth://broker_bundle_id", context: nil)
102+
103+
XCTAssertNotNil(response)
104+
XCTAssertEqual(response?.actionUri, "some_uri")
105+
XCTAssertEqual(response?.switchBrowserSessionToken, "some_code")
106+
XCTAssertEqual(response?.useEphemeralWebBrowserSession, false)
107+
}
108+
85109
func testInit_whenInvalidUrl_shouldReturnNil() throws
86110
{
87111
let url = URL(string: "msauth.com.microsoft.msaltestapp://auth/abc?action_uri=some_uri&code=some_code")!

0 commit comments

Comments
 (0)