Skip to content

Commit 5481a72

Browse files
Fidelia NawarFidelia Nawar
authored andcommitted
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentication-library-common-for-objc into fidelianawar/sts_error_mapping
2 parents 0991c8a + 5d8d96e commit 5481a72

30 files changed

+3754
-30
lines changed

.github/workflows/auto-retag.yml

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Auto-retag UNTAGGED entries
2+
3+
# This workflow automatically fixes UNTAGGED entries and commits the changes
4+
# Trigger manually via workflow_dispatch or on push to specific branches
5+
6+
on:
7+
workflow_dispatch: # Manual trigger
8+
push:
9+
branches:
10+
- '**' # All branches
11+
paths:
12+
- 'IdentityCore/src/telemetry/execution_flow/MSIDExecutionFlowConstants.m'
13+
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
issues: write
18+
19+
env:
20+
TAG_PLACEHOLDER: "UNTAGGED"
21+
TAG_LENGTH: "5"
22+
TAG_CHARSET: "abcdefghijklmnopqrstuvwxyz0123456789"
23+
24+
jobs:
25+
auto-retag:
26+
name: Automatically retag UNTAGGED entries
27+
runs-on: ubuntu-latest
28+
29+
# Skip if the commit was made by github-actions bot (prevents infinite loop)
30+
if: github.actor != 'github-actions[bot]'
31+
32+
steps:
33+
- name: Checkout code
34+
uses: actions/checkout@v4
35+
with:
36+
token: ${{ secrets.GITHUB_TOKEN }}
37+
ref: ${{ github.head_ref || github.ref }}
38+
39+
- name: Set up Python
40+
uses: actions/setup-python@v5
41+
with:
42+
python-version: '3.x'
43+
44+
- name: Run retag script
45+
id: retag
46+
run: |
47+
OUTPUT=$(python scripts/retag_untagged.py --placeholder "${{ env.TAG_PLACEHOLDER }}" --length "${{ env.TAG_LENGTH }}" --charset "${{ env.TAG_CHARSET }}" 2>&1)
48+
echo "$OUTPUT"
49+
echo "output<<EOF" >> $GITHUB_OUTPUT
50+
echo "$OUTPUT" >> $GITHUB_OUTPUT
51+
echo "EOF" >> $GITHUB_OUTPUT
52+
53+
- name: Check if file was modified
54+
id: check_changes
55+
run: |
56+
if git diff --quiet IdentityCore/src/telemetry/execution_flow/MSIDExecutionFlowConstants.m; then
57+
echo "has_changes=false" >> $GITHUB_OUTPUT
58+
echo "No changes made - file already has all tags assigned"
59+
else
60+
echo "has_changes=true" >> $GITHUB_OUTPUT
61+
echo "Changes detected - UNTAGGED entries were replaced"
62+
fi
63+
64+
- name: Commit and push changes
65+
if: steps.check_changes.outputs.has_changes == 'true'
66+
run: |
67+
git config user.name "github-actions[bot]"
68+
git config user.email "github-actions[bot]@users.noreply.github.com"
69+
git add IdentityCore/src/telemetry/execution_flow/MSIDExecutionFlowConstants.m
70+
git commit -m "Auto-retag UNTAGGED execution flow tags [skip ci]"
71+
git push
72+
73+
- name: No changes needed
74+
if: steps.check_changes.outputs.has_changes == 'false'
75+
run: echo "✓ All tags are already assigned. No action needed."
76+
77+
- name: Post PR comment
78+
if: steps.check_changes.outputs.has_changes == 'true'
79+
uses: actions/github-script@v7
80+
with:
81+
script: |
82+
const output = `${{ steps.retag.outputs.output }}`;
83+
const placeholder = `${{ env.TAG_PLACEHOLDER }}`;
84+
85+
// Get the current branch name
86+
const branch = context.ref.replace('refs/heads/', '');
87+
88+
// Find open PRs for this branch
89+
const { data: prs } = await github.rest.pulls.list({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
state: 'open',
93+
head: `${context.repo.owner}:${branch}`
94+
});
95+
96+
// If there's an open PR, comment on it
97+
if (prs.length > 0) {
98+
const pr = prs[0];
99+
await github.rest.issues.createComment({
100+
issue_number: pr.number,
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
body: `## 🏷️ Auto-retag Results\n\n\`\`\`\n${output}\n\`\`\`\n\n✅ ${placeholder} entries have been automatically replaced with unique tags.`
104+
});
105+
console.log(`Posted comment to PR #${pr.number}`);
106+
} else {
107+
console.log('No open PR found for this branch - skipping comment');
108+
}

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 86 additions & 0 deletions
Large diffs are not rendered by default.

IdentityCore/src/MSIDConstants.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,16 @@ extern NSString * _Nonnull const MSID_FLIGHT_IS_BART_SUPPORTED;
244244
extern NSString * _Nonnull const MSID_FLIGHT_SPINNER_FIX;
245245

246246
extern NSString * _Nonnull const MSID_FLIGHT_ENABLE_QUERYING_STK;
247+
248+
/// Owner: sedemche
247249
extern NSString * _Nonnull const MSID_FLIGHT_USE_AUTOLAYOUT_FOR_LOADING_INDICATOR;
248250

251+
/// Owner: sedemche
252+
extern NSString * _Nonnull const MSID_FLIGHT_BROWSER_CORE_DISABLE_POP;
253+
254+
/// Owner: sedemche
255+
extern NSString * _Nonnull const MSID_FLIGHT_BROWSER_CORE_DISABLE_CLAIMS;
256+
249257
extern NSString * _Nonnull const MSID_DOMAIN_HINT_KEY;
250258

251259
extern NSString * _Nonnull const MSID_FLIGHT_ENABLE_THREAD_STARVATION;

IdentityCore/src/MSIDConstants.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@
102102

103103
NSString *const MSID_FLIGHT_USE_AUTOLAYOUT_FOR_LOADING_INDICATOR = @"use_autolayout_for_loading_indicator";
104104

105+
NSString *const MSID_FLIGHT_BROWSER_CORE_DISABLE_POP = @"browser_core_disable_pop";
106+
107+
NSString *const MSID_FLIGHT_BROWSER_CORE_DISABLE_CLAIMS = @"browser_core_disable_claims";
108+
105109
NSString *const MSID_DOMAIN_HINT_KEY = @"domain_hint";
106110

107111
// This is SsoExt flow only flight

IdentityCore/src/broker_operation/request/browser_native_message_request/MSIDBrowserNativeMessageGetTokenRequest.m

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#import "MSIDAuthenticationSchemePop.h"
3333
#import "MSIDAuthScheme.h"
3434
#import "MSIDClaimsRequest.h"
35+
#import "MSIDFlightManager.h"
3536

3637
NSString *const MSID_BROWSER_NATIVE_MESSAGE_CLIENT_ID_KEY = @"clientId";
3738
NSString *const MSID_BROWSER_NATIVE_MESSAGE_AUTHORITY_KEY = @"authority";
@@ -178,36 +179,45 @@ - (instancetype)initWithJSONDictionary:(NSDictionary *)json error:(NSError *__au
178179
// It is optional param, if nil -- set it to 'true' by default.
179180
_canShowUI = canShowUIValue ? [requestJson msidBoolObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CAN_SHOW_UI_KEY] : YES;
180181

181-
NSString *reqCnf = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_CONFIRMATION_KEY] ?: [_extraParameters msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_CONFIRMATION_KEY];
182-
NSString *tokenType = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_TOKEN_TYPE_KEY] ?: [_extraParameters msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_TOKEN_TYPE_KEY];
183-
tokenType = tokenType.capitalizedString;
182+
BOOL disablePop = [MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_BROWSER_CORE_DISABLE_POP];
184183

185-
186-
if (MSIDAuthSchemeTypeFromString(tokenType) == MSIDAuthSchemePop)
184+
if (!disablePop)
187185
{
188-
NSMutableDictionary *schemeParams = [NSMutableDictionary new];
189-
schemeParams[MSID_OAUTH2_TOKEN_TYPE] = tokenType;
190-
schemeParams[MSID_OAUTH2_REQUEST_CONFIRMATION] = reqCnf;
186+
NSString *reqCnf = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_CONFIRMATION_KEY] ?: [_extraParameters msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_REQUEST_CONFIRMATION_KEY];
187+
NSString *tokenType = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_TOKEN_TYPE_KEY] ?: [_extraParameters msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_TOKEN_TYPE_KEY];
188+
tokenType = tokenType.capitalizedString;
191189

192-
_authScheme = [[MSIDAuthenticationSchemePop alloc] initWithSchemeParameters:schemeParams];
190+
if (MSIDAuthSchemeTypeFromString(tokenType) == MSIDAuthSchemePop)
191+
{
192+
NSMutableDictionary *schemeParams = [NSMutableDictionary new];
193+
schemeParams[MSID_OAUTH2_TOKEN_TYPE] = tokenType;
194+
schemeParams[MSID_OAUTH2_REQUEST_CONFIRMATION] = reqCnf;
195+
196+
_authScheme = [[MSIDAuthenticationSchemePop alloc] initWithSchemeParameters:schemeParams];
197+
}
193198
}
194199

195200
if (!_authScheme)
196201
{
197202
_authScheme = [MSIDAuthenticationScheme new]; // Bearer by default.
198203
}
199-
200-
NSString *claims = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CLAIMS_KEY] ?: [_extraParameters msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CLAIMS_KEY];
201204

202-
if (claims)
205+
BOOL disableClaims = [MSIDFlightManager.sharedInstance boolForKey:MSID_FLIGHT_BROWSER_CORE_DISABLE_CLAIMS];
206+
207+
if (!disableClaims)
203208
{
204-
NSDictionary *claimsJson = [claims msidJson];
209+
NSString *claims = [requestJson msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CLAIMS_KEY] ?: [_extraParameters msidStringObjectForKey:MSID_BROWSER_NATIVE_MESSAGE_CLAIMS_KEY];
205210

206-
NSError *claimsError;
207-
_claimsRequest = [[MSIDClaimsRequest alloc] initWithJSONDictionary:claimsJson error:&claimsError];
208-
if (claimsError)
211+
if (claims)
209212
{
210-
MSID_LOG_WITH_CTX(MSIDLogLevelWarning, nil, @"Failed to create claims request. Claims: %@", MSID_PII_LOG_MASKABLE(claimsJson));
213+
NSDictionary *claimsJson = [claims msidJson];
214+
215+
NSError *claimsError;
216+
_claimsRequest = [[MSIDClaimsRequest alloc] initWithJSONDictionary:claimsJson error:&claimsError];
217+
if (claimsError)
218+
{
219+
MSID_LOG_WITH_CTX(MSIDLogLevelWarning, nil, @"Failed to create claims request. Claims: %@", MSID_PII_LOG_MASKABLE(claimsJson));
220+
}
211221
}
212222
}
213223

IdentityCore/src/network/MSIDHttpRequest.m

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#import "MSIDOAuthRequestConfigurator.h"
3434
#import "MSIDHttpRequestServerTelemetryHandling.h"
3535
#import "MSIDBrokerConstants.h"
36+
#import "MSIDExecutionFlowLogger.h"
37+
#import "MSIDExecutionFlowConstants.h"
3638

3739
static NSInteger s_retryCount = 1;
3840
static NSTimeInterval s_retryInterval = 0.5;
@@ -76,7 +78,9 @@ - (instancetype)init
7678
- (void)sendWithBlock:(MSIDHttpRequestDidCompleteBlock)completionBlock
7779
{
7880
NSParameterAssert(self.urlRequest);
79-
81+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:[self toString:MSIDExecutionFlowPrepareNetworkRequestTag]
82+
extraInfo:nil
83+
withCorrelationId:self.context.correlationId];
8084
__auto_type requestConfigurator = [MSIDOAuthRequestConfigurator new];
8185
requestConfigurator.timeoutInterval = _requestTimeoutInterval;
8286
[requestConfigurator configure:self];
@@ -99,11 +103,17 @@ - (void)sendWithBlock:(MSIDHttpRequestDidCompleteBlock)completionBlock
99103

100104
if (!responseObject)
101105
{
106+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:[self toString:MSIDExecutionFlowCacheResponseFailedObjectTag]
107+
extraInfo:nil
108+
withCorrelationId:self.context.correlationId];
102109
[self.cache removeCachedResponseForRequest:self.urlRequest];
103110
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose,self.context, @"Removing invalid response from cache %@, response: %@", _PII_NULLIFY(self.urlRequest), _PII_NULLIFY(response.response));
104111
}
105112
else
106113
{
114+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:[self toString:MSIDExecutionFlowCacheResponseSucceededObjectTag]
115+
extraInfo:nil
116+
withCorrelationId:self.context.correlationId];
107117
if (completionBlock) { completionBlock(responseObject, error); }
108118
return;
109119
}
@@ -117,6 +127,9 @@ - (void)sendWithBlock:(MSIDHttpRequestDidCompleteBlock)completionBlock
117127

118128
[[self.sessionManager.session dataTaskWithRequest:self.urlRequest completionHandler:^(NSData *data, NSURLResponse *urlResponse, NSError *error)
119129
{
130+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:[self toString:MSIDExecutionFlowReceiveNetworkResponseTag]
131+
extraInfo:nil
132+
withCorrelationId:self.context.correlationId];
120133
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose,self.context, @"Received network response: %@, error %@", _PII_NULLIFY(urlResponse), _PII_NULLIFY(error));
121134

122135
if (urlResponse) NSAssert([urlResponse isKindOfClass:NSHTTPURLResponse.class], NULL);
@@ -132,6 +145,9 @@ - (void)sendWithBlock:(MSIDHttpRequestDidCompleteBlock)completionBlock
132145

133146
void (^completeBlockWrapper)(id, NSError *) = ^(id wrapperResponse, NSError *wrapperError)
134147
{
148+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:[self toString:MSIDExecutionFlowParseNetworkResponseTag]
149+
extraInfo:wrapperError ? @{MSID_EXECUTION_FLOW_ERROR_CODE:@(wrapperError.code)} : nil
150+
withCorrelationId:self.context.correlationId];
135151
[self.serverTelemetry handleError:wrapperError context:self.context];
136152

137153
if (completionBlock) { completionBlock(wrapperResponse, wrapperError); }
@@ -140,7 +156,7 @@ - (void)sendWithBlock:(MSIDHttpRequestDidCompleteBlock)completionBlock
140156
if (error)
141157
{
142158
if ([self.experimentBag msidBoolObjectForKey:MSID_EXP_RETRY_ON_NETWORK])
143-
{
159+
{
144160
[self.errorHandler handleError:error
145161
httpResponse:nil
146162
data:nil
@@ -171,6 +187,10 @@ - (void)sendWithBlock:(MSIDHttpRequestDidCompleteBlock)completionBlock
171187
}
172188
else
173189
{
190+
191+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:[self toString:MSIDExecutionFlowOtherHttpNetworkStatusCodeTag]
192+
extraInfo:@{MSID_EXECUTION_FLOW_DIAGNOSTIC_ID:@(httpResponse.statusCode)}
193+
withCorrelationId:self.context.correlationId];
174194
if (self.errorHandler)
175195
{
176196
id<MSIDResponseSerialization> responseSerializer = self.errorResponseSerializer ? self.errorResponseSerializer : self.responseSerializer;
@@ -208,9 +228,14 @@ - (NSCachedURLResponse *)cachedResponse
208228
return [self.cache cachedResponseForRequest:self.urlRequest];
209229
}
210230

211-
-(void)setCachedResponse:(__unused NSCachedURLResponse *)cachedResponse forRequest:(__unused NSURLRequest *)request
231+
- (void)setCachedResponse:(__unused NSCachedURLResponse *)cachedResponse forRequest:(__unused NSURLRequest *)request
212232
{
213233
[self.cache storeCachedResponse:cachedResponse forRequest:request];
214234
}
215235

236+
- (NSString *)toString:(MSIDExecutionFlowNetworkTag)tag
237+
{
238+
return MSIDExecutionFlowNetworkTagToString(tag);
239+
}
240+
216241
@end

IdentityCore/src/network/error_handler/MSIDAADRequestErrorHandler.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#import "MSIDWorkPlaceJoinConstants.h"
3030
#import "MSIDPKeyAuthHandler.h"
3131
#import "MSIDMainThreadUtil.h"
32+
#import "MSIDExecutionFlowLogger.h"
33+
#import "MSIDExecutionFlowConstants.h"
3234

3335
@implementation MSIDAADRequestErrorHandler
3436

@@ -72,11 +74,17 @@ - (void)handleError:(NSError *)error
7274

7375
if (shouldRetry)
7476
{
77+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:MSIDExecutionFlowNetworkTagToString(MSIDExecutionFlowRetryOnNetworkFailureTag)
78+
extraInfo:nil
79+
withCorrelationId:context.correlationId];
7580
httpRequest.retryCounter--;
7681

7782
MSID_LOG_WITH_CTX(MSIDLogLevelVerbose,context, @"Retrying network request, retryCounter: %ld", (long)httpRequest.retryCounter);
7883

7984
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(httpRequest.retryInterval * NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
85+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:MSIDExecutionFlowNetworkTagToString(MSIDExecutionFlowStartToRetryOnNetworkFailureTag)
86+
extraInfo:nil
87+
withCorrelationId:context.correlationId];
8088
[httpRequest sendWithBlock:completionBlock];
8189
});
8290

IdentityCore/src/requests/MSIDSilentTokenRequest.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
#import "MSIDDefaultTokenCacheAccessor.h"
5151
#import "MSIDAccountCredentialCache.h"
5252
#import "MSIDKeychainTokenCache.h"
53+
#import "MSIDExecutionFlowLogger.h"
54+
#import "MSIDExecutionFlowConstants.h"
5355

5456
#if TARGET_OS_OSX && !EXCLUDE_FROM_MSALCPP
5557
#import "MSIDExternalAADCacheSeeder.h"
@@ -184,6 +186,13 @@ - (void)executeRequestImpl:(MSIDRequestCompletionBlock)completionBlock
184186
if (accessToken)
185187
{
186188
accessTokenExpired = [accessToken isExpiredWithExpiryBuffer:self.requestParameters.tokenExpirationBuffer];
189+
if (accessToken.cachedAt)
190+
{
191+
NSTimeInterval elapsed = [[NSDate date] timeIntervalSinceDate:accessToken.expiresOn];
192+
[[MSIDExecutionFlowLogger sharedInstance] insertTag:MSIDTokenRequestTagToString(MSIDTokenRequestAtExpirationElapsedTag)
193+
extraInfo:@{MSID_EXECUTION_FLOW_DIAGNOSTIC_ID:@((int64_t)elapsed)}
194+
withCorrelationId:self.requestParameters.correlationId];
195+
}
187196
}
188197

189198
if (accessToken && ![NSString msidIsStringNilOrBlank:accessToken.kid])

0 commit comments

Comments
 (0)