Skip to content

Commit 3a7c38e

Browse files
authored
Merge pull request #1551 from AzureAD/sedemche/browser_core_mats
Return MATS blob for GetToken api response
2 parents 666dde7 + 1ade20e commit 3a7c38e

File tree

10 files changed

+630
-1
lines changed

10 files changed

+630
-1
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@
116116
23185367206D8B090024DCA4 /* MSIDTestConfiguration.m in Sources */ = {isa = PBXBuildFile; fileRef = B23ECEFF1FF306110015FC1D /* MSIDTestConfiguration.m */; };
117117
23185368206D8B1D0024DCA4 /* MSIDTestTokenResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = B23ECEFB1FF304250015FC1D /* MSIDTestTokenResponse.m */; };
118118
23185369206D8B1E0024DCA4 /* MSIDTestTokenResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = B23ECEFB1FF304250015FC1D /* MSIDTestTokenResponse.m */; };
119+
2318D7842E11664700A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.h in Headers */ = {isa = PBXBuildFile; fileRef = 2318D7832E11664300A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.h */; };
120+
2318D7862E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 2318D7852E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m */; };
121+
2318D7872E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m in Sources */ = {isa = PBXBuildFile; fileRef = 2318D7852E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m */; };
122+
2318D7892E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2318D7882E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m */; };
123+
2318D78A2E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2318D7882E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m */; };
119124
231CE9A11FE86EA300E95D3E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 231CE9A01FE86EA300E95D3E /* main.m */; };
120125
231CE9A41FE86EA300E95D3E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 231CE9A31FE86EA300E95D3E /* AppDelegate.m */; };
121126
231CE9A71FE86EA300E95D3E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 231CE9A61FE86EA300E95D3E /* ViewController.m */; };
@@ -2137,6 +2142,9 @@
21372142
230FF0D524BE93BE00A4DC6B /* MSIDLoggerConnecting.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDLoggerConnecting.h; sourceTree = "<group>"; };
21382143
2317FFBE2A44FDD300E3DAA2 /* MSIDBrowserNativeMessageGetCookiesRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBrowserNativeMessageGetCookiesRequest.h; sourceTree = "<group>"; };
21392144
2317FFBF2A44FDD400E3DAA2 /* MSIDBrowserNativeMessageGetCookiesRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrowserNativeMessageGetCookiesRequest.m; sourceTree = "<group>"; };
2145+
2318D7832E11664300A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MSIDBrokerOperationBrowserNativeMessageMATSReport.h; sourceTree = "<group>"; };
2146+
2318D7852E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrokerOperationBrowserNativeMessageMATSReport.m; sourceTree = "<group>"; };
2147+
2318D7882E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m; sourceTree = "<group>"; };
21402148
231CE99D1FE86EA300E95D3E /* MSIDTestsHostApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MSIDTestsHostApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
21412149
231CE9A01FE86EA300E95D3E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
21422150
231CE9A21FE86EA300E95D3E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -3885,6 +3893,8 @@
38853893
2371A6102A4BAB28008A71F3 /* browser_native_message_response */ = {
38863894
isa = PBXGroup;
38873895
children = (
3896+
2318D7832E11664300A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.h */,
3897+
2318D7852E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m */,
38883898
2371A6112A4BAB28008A71F3 /* MSIDBrokerOperationBrowserNativeMessageResponse.h */,
38893899
2371A6122A4BAB28008A71F3 /* MSIDBrokerOperationBrowserNativeMessageResponse.m */,
38903900
2371A6162A4BAB43008A71F3 /* MSIDBrowserNativeMessageGetCookiesResponse.h */,
@@ -5734,6 +5744,7 @@
57345744
D6DA89731FBA6A4E004C56C7 /* tests */ = {
57355745
isa = PBXGroup;
57365746
children = (
5747+
2318D7882E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m */,
57375748
72C764F82E09CFA400043AB1 /* MSIDBoundRefreshTokenTests.m */,
57385749
720B5B572DD58A6A00318FE5 /* MSIDJWECryptoTests.m */,
57395750
729357F22DDBD3F60001D03C /* MSIDNonceTokenRequestTest.m */,
@@ -6064,6 +6075,7 @@
60646075
2306D2B520AD05A700F875A3 /* MSIDURLSessionDelegate.h in Headers */,
60656076
1E2EDFF9219125400054FAD9 /* MSIDTokenResponse+Internal.h in Headers */,
60666077
238E19E02086FE28004DF483 /* MSIDAADRefreshTokenGrantRequest.h in Headers */,
6078+
2318D7842E11664700A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.h in Headers */,
60676079
B286B9A62389DD1E007833AD /* MSIDSystemWebviewController.h in Headers */,
60686080
B286B9AF2389DD63007833AD /* MSIDClientTLSHandler.h in Headers */,
60696081
74D926C324B3EFC300AA4270 /* MSIDLastRequestTelemetry+Internal.h in Headers */,
@@ -7076,6 +7088,7 @@
70767088
239DF9BF20E04BC9002D428B /* MSIDAADAuthorityTests.m in Sources */,
70777089
96CD653020C8ACBE004813EE /* MSIDWebviewResponseTests.m in Sources */,
70787090
23419F7C239B0D1C00EA78C5 /* MSIDAuthorityTests.m in Sources */,
7091+
2318D7892E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m in Sources */,
70797092
1E4252352187DA0D00C149E9 /* MSIDAppMetadataCacheQueryTests.m in Sources */,
70807093
B2DD4B2E20A8D7DE0047A66E /* MSIDCacheKeyTests.m in Sources */,
70817094
B25D496421B4BE2A00502BE5 /* MSIDRequestParametersTests.m in Sources */,
@@ -7614,6 +7627,7 @@
76147627
96448C9D20CF296C00E2D89C /* MSIDAADWebviewFactory.m in Sources */,
76157628
2385DD922D13A5F40075D080 /* MSIDSwitchBrowserResponse.m in Sources */,
76167629
96B8D57C20946D2600E3F4A6 /* MSIDPkce.m in Sources */,
7630+
2318D7872E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m in Sources */,
76177631
2A59B42E2D776F3400304FB1 /* MSIDXpcConfiguration.m in Sources */,
76187632
6057EE9120B5FDF8007976EB /* MSIDAADOAuthEmbeddedWebviewController.m in Sources */,
76197633
238E19DF2086FE28004DF483 /* MSIDTokenRequest.m in Sources */,
@@ -7782,6 +7796,7 @@
77827796
23FB5C21225516FB002BF1EB /* MSIDClaimsRequestTests.m in Sources */,
77837797
E75DD02625D5E474007664A6 /* MSIDThrottlingServiceIntegrationTests.m in Sources */,
77847798
B286BA07238A110A007833AD /* MSIDOIDCSignoutRequestTests.m in Sources */,
7799+
2318D78A2E12B8E800A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReportTests.m in Sources */,
77857800
B280800E204CD82100944D89 /* MSIDDefaultCredentialCacheKeyTests.m in Sources */,
77867801
23F7A8642A61F21E002C70CB /* MSIDBrowserNativeMessageGetCookiesResponseTests.m in Sources */,
77877802
B431B5272AF05B3F0020CD3D /* MSIDBrokerOperationPasskeyCredentialRequestTests.m in Sources */,
@@ -8355,6 +8370,7 @@
83558370
A0C7DEC325D4C8B600F5B5B6 /* MSIDThrottlingModel429.m in Sources */,
83568371
B297E1E720A12BDE00F370EC /* MSIDDefaultAccountCacheKey.m in Sources */,
83578372
F7AB25B36873F2E237D26F68 /* MSIDWPJMetadata.m in Sources */,
8373+
2318D7862E11763C00A5A46E /* MSIDBrokerOperationBrowserNativeMessageMATSReport.m in Sources */,
83588374
);
83598375
runOnlyForDeploymentPostprocessing = 0;
83608376
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
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+
#import <Foundation/Foundation.h>
26+
#import "MSIDJsonSerializable.h"
27+
#import "MSIDConstants.h"
28+
29+
NS_ASSUME_NONNULL_BEGIN
30+
31+
/**
32+
* MATS Silent Status Enum
33+
*
34+
* Represents the outcome of a silent token request attempt.
35+
* Based on WebTokenRequestStatus values used in Windows WAM.
36+
*/
37+
typedef NS_ENUM(NSInteger, MSIDMATSSilentStatus) {
38+
/**
39+
* Silent token obtained successfully
40+
*/
41+
MSIDMATSSilentStatusSuccess = 0,
42+
43+
/**
44+
* User cancelled the silent token request
45+
*/
46+
MSIDMATSSilentStatusUserCancel = 1,
47+
48+
/**
49+
* Silent attempt concluded that user interaction is required
50+
*/
51+
MSIDMATSSilentStatusUserInteractionRequired = 3,
52+
53+
/**
54+
* Silent attempt hit a provider error (e.g., refresh token expired)
55+
*/
56+
MSIDMATSSilentStatusProviderError = 5
57+
};
58+
59+
typedef NSString *MSIDMATSDeviceJoinStatus NS_TYPED_ENUM;
60+
extern MSIDMATSDeviceJoinStatus const MSIDMATSDeviceJoinStatusNotJoined;
61+
extern MSIDMATSDeviceJoinStatus const MSIDMATSDeviceJoinStatusAADJ;
62+
63+
/**
64+
* Microsoft Authentication Telemetry System (MATS) Report
65+
*
66+
* This class represents detailed telemetry information about the token acquisition process
67+
* that the native broker returns to MSAL.js. MSAL.js will record these fields in its
68+
* telemetry if the broker provides them. This telemetry helps correlate broker operations
69+
* (like cache hits, device state, or errors) with MSAL.js events.
70+
*/
71+
@interface MSIDBrokerOperationBrowserNativeMessageMATSReport : NSObject <MSIDJsonSerializable>
72+
73+
/**
74+
* Indicates if the token came from cache.
75+
*
76+
* A boolean flag where YES (1) means the broker returned a cached token without a network call,
77+
* and NO (0) means a network request was made to acquire a new token. This helps measure
78+
* how often silent SSO worked via cache vs network.
79+
*
80+
* Example: YES (token was served from cache), NO (fresh call required)
81+
*/
82+
@property (nonatomic) BOOL isCached;
83+
84+
/**
85+
* Version of the broker handling the request.
86+
*
87+
* Example: "3.9.0"
88+
*/
89+
@property (nonatomic, nullable) NSString *brokerVersion;
90+
91+
/**
92+
* Device's AAD join status.
93+
*
94+
* Indicates the device's registration state in Entra ID (Azure AD). Possible values:
95+
* - MSIDMATSDeviceJoinStatusAADJ (@"aadj") - Device is Azure AD joined (managed by org)
96+
* - MSIDMATSDeviceJoinStatusNotJoined (@"not_joined") - Device is not joined to AAD
97+
* This field helps identify if device is corporate-managed or personal.
98+
*
99+
* Example: MSIDMATSDeviceJoinStatusAADJ (managed device), MSIDMATSDeviceJoinStatusNotJoined (personal device)
100+
*/
101+
@property (nonatomic, nullable) MSIDMATSDeviceJoinStatus deviceJoin;
102+
103+
/**
104+
* Type of prompt that occurred.
105+
*/
106+
@property (nonatomic) MSIDPromptType promptBehavior;
107+
108+
/**
109+
* Broker/IDP error code.
110+
*
111+
* A numeric code representing the error if the token request failed. 0 if the operation
112+
* succeeded or no specific error.
113+
*
114+
* Example: 0 (no error, success)
115+
*/
116+
@property (nonatomic) NSInteger apiErrorCode;
117+
118+
/**
119+
* Was UI shown?
120+
*
121+
* Boolean flag: YES if the broker showed any UI to the user. NO if the entire flow was silent/invisible.
122+
* This directly indicates if the user was interrupted with a prompt.
123+
*
124+
* Example: YES (user saw sign-in window), NO (completely silent SSO).
125+
*/
126+
@property (nonatomic) BOOL uiVisible;
127+
128+
/**
129+
* Silent attempt error code.
130+
*
131+
* If the broker attempted to get a token silently (using cached credentials or refresh
132+
* token) and that attempt failed, this is the error code from the silent try. 0 if
133+
* silent succeeded or no error was encountered silently.
134+
*
135+
* Example: 0 (silent succeeded or not attempted)
136+
*/
137+
@property (nonatomic) NSInteger silentCode;
138+
139+
/**
140+
* Silent attempt error message.
141+
*
142+
* A short text description of why the silent attempt failed, if an error occurred.
143+
* Including this helps debugging exact silent failure reasons.
144+
*
145+
* Example: @"" (silent succeeded), @"The web page and the redirect uri must be on the same origin."
146+
*/
147+
@property (nonatomic, nullable) NSString *silentMessage;
148+
149+
/**
150+
* Outcome of silent request (status code).
151+
*
152+
* Corresponds to the broker's internal status enum for a silent token attempt.
153+
* Values based on WebTokenRequestStatus:
154+
* - MSIDMATSSilentStatusSuccess (0) - Silent token obtained successfully
155+
* - MSIDMATSSilentStatusUserCancel (1) - User cancelled the silent token request
156+
* - MSIDMATSSilentStatusUserInteractionRequired (3) - Silent attempt concluded that user interaction is required
157+
* - MSIDMATSSilentStatusProviderError (5) - Silent attempt hit a provider error
158+
*
159+
* Example: MSIDMATSSilentStatusSuccess (silent success), MSIDMATSSilentStatusUserInteractionRequired (interaction required)
160+
*/
161+
@property (nonatomic) MSIDMATSSilentStatus silentStatus;
162+
163+
/**
164+
* HTTP response code from token endpoint.
165+
*
166+
* If the broker made a network request to AAD (for token, device code, etc.), this
167+
* captures the HTTP status code. 200 for success, 4xx/5xx for various errors.
168+
* Will be 0 if no network call occurred (e.g., fully cached token).
169+
*
170+
* Example: 200 (token obtained successfully), 400 (bad request), 500 (server error)
171+
*/
172+
@property (nonatomic) NSInteger httpStatus;
173+
174+
/**
175+
* JSON string representation of the report.
176+
*
177+
* Converts the MATS report into a JSON string format for easy logging or transmission.
178+
*
179+
* @return A JSON string representing the MATS report, or nil if serialization fails.
180+
*/
181+
- (NSString *)jsonString;
182+
183+
@end
184+
185+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)