Skip to content

Commit a9c8443

Browse files
authored
Merge pull request #153 from AzureAD/jak/error-coding
Error code & other related tasks refactoring
2 parents bf0c8dc + 330fcd8 commit a9c8443

34 files changed

+249
-132
lines changed

IdentityCore/IdentityCore.xcodeproj/project.pbxproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@
134134
6035CD8D207EA67300369E69 /* MSIDTelemetryIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6035CD8B207EA67300369E69 /* MSIDTelemetryIntegrationTests.m */; };
135135
6057EE9020B5FDF8007976EB /* MSIDAADOAuthEmbeddedWebviewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6057EE8F20B5FDF8007976EB /* MSIDAADOAuthEmbeddedWebviewController.m */; };
136136
6057EE9120B5FDF8007976EB /* MSIDAADOAuthEmbeddedWebviewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 6057EE8F20B5FDF8007976EB /* MSIDAADOAuthEmbeddedWebviewController.m */; };
137-
606830052098ACED00CCA6AB /* MSIDNegotiateHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 606830042098ACED00CCA6AB /* MSIDNegotiateHandler.m */; };
138137
606830062098ACED00CCA6AB /* MSIDNegotiateHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 606830042098ACED00CCA6AB /* MSIDNegotiateHandler.m */; };
139138
6068300A2098C9D300CCA6AB /* MSIDCredentialCollectionController.m in Sources */ = {isa = PBXBuildFile; fileRef = 606830092098C9D300CCA6AB /* MSIDCredentialCollectionController.m */; };
140139
606830102098E94100CCA6AB /* MSIDCertificateChooser.m in Sources */ = {isa = PBXBuildFile; fileRef = 6068300F2098E94100CCA6AB /* MSIDCertificateChooser.m */; };
@@ -149,7 +148,6 @@
149148
60BF06042051F9A200DE7C1C /* MSIDTelemetryTestDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 60BF06032051F9A200DE7C1C /* MSIDTelemetryTestDispatcher.m */; };
150149
60BF06052051F9A200DE7C1C /* MSIDTelemetryTestDispatcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 60BF06032051F9A200DE7C1C /* MSIDTelemetryTestDispatcher.m */; };
151150
60D6ED0220D9BB02002FCBBB /* SecurityInterface.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9623FF4220A396F700A989B7 /* SecurityInterface.framework */; };
152-
60D6ED0420D9BB50002FCBBB /* GSS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 60D6ED0320D9BB4F002FCBBB /* GSS.framework */; };
153151
60D6ED0620D9BB5A002FCBBB /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 60D6ED0520D9BB5A002FCBBB /* WebKit.framework */; };
154152
60D6ED0820D9BB6A002FCBBB /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 60D6ED0720D9BB6A002FCBBB /* UIKit.framework */; };
155153
60D6ED0A20D9BB79002FCBBB /* SafariServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 60D6ED0920D9BB79002FCBBB /* SafariServices.framework */; };
@@ -1175,7 +1173,6 @@
11751173
60D6ED0A20D9BB79002FCBBB /* SafariServices.framework in Frameworks */,
11761174
60D6ED0820D9BB6A002FCBBB /* UIKit.framework in Frameworks */,
11771175
60D6ED0620D9BB5A002FCBBB /* WebKit.framework in Frameworks */,
1178-
60D6ED0420D9BB50002FCBBB /* GSS.framework in Frameworks */,
11791176
96285D6320D872AA004CA4BD /* libIdentityCore.a in Frameworks */,
11801177
96285D6120D8721E004CA4BD /* libIdentityTest.a in Frameworks */,
11811178
);
@@ -3037,7 +3034,6 @@
30373034
B29A36C020B1289D00427B63 /* MSIDAccountIdentifier.m in Sources */,
30383035
96A3E9B9208941D700BE5262 /* MSIDSystemWebviewController.m in Sources */,
30393036
D61AFAB51FD8B6C600DABBE5 /* MSIDConstants.m in Sources */,
3040-
606830052098ACED00CCA6AB /* MSIDNegotiateHandler.m in Sources */,
30413037
238E19CD2086FC87004DF483 /* MSIDUrlRequestSerializer.m in Sources */,
30423038
96F21B0520A4FB27002B87C3 /* MSIDAppExtensionUtil.m in Sources */,
30433039
238E19DE2086FE28004DF483 /* MSIDTokenRequest.m in Sources */,
@@ -3584,13 +3580,18 @@
35843580
isa = XCBuildConfiguration;
35853581
baseConfigurationReference = D6CF4E931FC3626A00CD70C5 /* identitycore__debug.xcconfig */;
35863582
buildSettings = {
3583+
GCC_PREPROCESSOR_DEFINITIONS = (
3584+
"$(inherited)",
3585+
"$(MSID_SYSTEMWV)",
3586+
);
35873587
};
35883588
name = Debug;
35893589
};
35903590
D68FB48F1FBA698A005308BB /* Release */ = {
35913591
isa = XCBuildConfiguration;
35923592
baseConfigurationReference = D6CF4E9C1FC3626B00CD70C5 /* identitycore__release.xcconfig */;
35933593
buildSettings = {
3594+
GCC_PREPROCESSOR_DEFINITIONS = "$(MSID_SYSTEMWV)";
35943595
};
35953596
name = Release;
35963597
};

IdentityCore/IdentityCore.xcodeproj/xcshareddata/xcschemes/IdentityCore iOS.xcscheme

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29-
language = ""
30-
shouldUseLaunchSchemeArgsEnv = "YES"
31-
codeCoverageEnabled = "YES">
29+
codeCoverageEnabled = "YES"
30+
shouldUseLaunchSchemeArgsEnv = "YES">
3231
<Testables>
3332
<TestableReference
3433
skipped = "NO">
@@ -57,7 +56,6 @@
5756
buildConfiguration = "Debug"
5857
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5958
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
60-
language = ""
6159
launchStyle = "0"
6260
useCustomWorkingDirectory = "NO"
6361
ignoresPersistentStateOnLaunch = "NO"

IdentityCore/src/MSIDError.h

Lines changed: 72 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -41,81 +41,99 @@ extern NSString *MSIDKeychainErrorDomain;
4141

4242
typedef NS_ENUM(NSInteger, MSIDErrorCode)
4343
{
44-
MSIDErrorInternal = -51000,
45-
MSIDErrorInvalidInternalParameter = -51001,
46-
47-
MSIDErrorInvalidDeveloperParameter = -51002,
48-
MSIDErrorAmbiguousAuthority = -51003,
49-
MSIDErrorInteractionRequired = -51004,
50-
51-
MSIDErrorCacheMultipleUsers = -51005,
52-
5344
/*!
54-
MSID encounted an error when trying to store or retrieve items from
55-
keychain. Inspect NSUnderlyingError from the userInfo dictionary for
56-
more information about the specific error. Keychain error codes are
57-
documented in Apple's <Security/SecBase.h> header file
45+
====================================================
46+
General Errors (510xx, 511xx) - MSIDErrorDomain
47+
====================================================
5848
*/
59-
MSIDErrorTokenCacheItemFailure = -51006,
60-
MSIDErrorWrapperCacheFailure = -51007,
61-
MSIDErrorCacheBadFormat = -51008,
62-
MSIDErrorCacheVersionMismatch = -51009,
49+
// General internal errors that do not fall into one of the specific type
50+
// of an error described below.
51+
MSIDErrorInternal = -51100,
6352

64-
MSIDErrorServerInvalidResponse = -51010,
65-
MSIDErrorDeveloperAuthorityValidation = -51011,
66-
MSIDErrorServerRefreshTokenRejected = -51012,
67-
MSIDErrorServerOauth = -51013,
68-
MSIDErrorInvalidRequest = -51014,
69-
MSIDErrorInvalidClient = -51015,
70-
MSIDErrorInvalidGrant = -51016,
71-
MSIDErrorInvalidScope = -51017,
72-
MSIDErrorInvalidParameter = -51018,
73-
MSIDErrorUserCancel = -51019,
74-
/*!
75-
The authentication request was cancelled programmatically.
76-
*/
77-
MSIDErrorSessionCanceled = -51020,
53+
// Parameter errors
54+
MSIDErrorInvalidInternalParameter = -51111,
55+
MSIDErrorInvalidDeveloperParameter = -51112,
56+
57+
// Unsupported functionality
58+
MSIDErrorUnsupportedFunctionality = -51199,
59+
7860
/*!
79-
An interactive authentication session is already running with the
80-
SafariViewController visible. Another authentication session can not be
81-
launched yet.
61+
=========================================================
62+
Cache Errors (512xx) - MSIDErrorDomain
63+
=========================================================
8264
*/
83-
MSIDErrorInteractiveSessionAlreadyRunning = -51021,
65+
66+
// Multiple users found in cache when one was intended
67+
MSIDErrorCacheMultipleUsers = -51201,
68+
MSIDErrorCacheBadFormat = -51302,
69+
8470
/*!
85-
An interactive authentication session failed to start.
71+
=========================================================
72+
Server errors (514xx) - MSIDOAuthErrorDomain
73+
=========================================================
8674
*/
87-
MSIDErrorInteractiveSessionStartFailure = -51022,
75+
// Interaction Required
76+
MSIDErrorInteractionRequired = -51411,
8877

89-
MSIDErrorNoMainViewController = -51023,
90-
MSIDServerNonHttpsRedirect = -51024,
78+
// Server returned a response indicating an OAuth error
79+
MSIDErrorServerOauth = -51421,
80+
// Server returned an invalid response
81+
MSIDErrorServerInvalidResponse = -51422,
82+
// Server returned a refresh token reject response
83+
MSIDErrorServerRefreshTokenRejected = -51423,
84+
// Other specific server response errors
9185

92-
MSIDErrorUnsupportedFunctionality = -51025,
86+
MSIDErrorServerInvalidRequest = -51431,
87+
MSIDErrorServerInvalidClient = -51432,
88+
MSIDErrorServerInvalidGrant = -51433,
89+
MSIDErrorServerInvalidScope = -51434,
90+
91+
// State verification has failed
92+
MSIDErrorServerInvalidState = -51441,
93+
94+
// Redirect to non HTTPS detected
95+
MSIDErrorServerNonHttpsRedirect = -51451,
9396

9497
/*!
95-
The user or application failed to authenticate in the interactive flow.
96-
Inspect MSALOAuthErrorKey and MSALErrorDescriptionKey in the userInfo
97-
dictionary for more detailed information about the specific error.
98+
=========================================================
99+
Authority Validation (515xx) - MSIDErrorDomain
100+
=========================================================
98101
*/
99-
MSIDErrorAuthorizationFailed = -52020,
102+
// Authority validation response failure
103+
MSIDErrorAuthorityValidation = -51500,
100104

101105
/*!
102-
Interaction required errors occur because of a wide variety of errors
103-
returned by the authentication service.
106+
=========================================================
107+
Interactive flow errors (516xx) - MSIDOAuthErrorDomain
108+
=========================================================
104109
*/
105-
MSIDErrorMismatchedUser = -52101,
106-
MSIDErrorNoAuthorizationResponse = -52102,
107-
MSIDErrorBadAuthorizationResponse = -52103,
108110

111+
// The user or application failed to authenticate in the interactive flow.
112+
// Inspect MSALOAuthErrorKey and MSALErrorDescriptionKey in the userInfo
113+
// dictionary for more detailed information about the specific error.
114+
MSIDErrorAuthorizationFailed = -51600,
115+
116+
// User has cancelled the interactive flow.
117+
MSIDErrorUserCancel = -51611,
118+
119+
// The interactive flow was cancelled programmatically.
120+
MSIDErrorSessionCanceledProgrammatically = -51612,
121+
122+
// Interactive authentication session failed to start.
123+
MSIDErrorInteractiveSessionStartFailure = -51621,
109124
/*!
110-
The state returned by the server does not match the state that was sent to
111-
the server at the beginning of the authorization attempt.
125+
An interactive authentication session is already running.
126+
Another authentication session can not be launched yet.
112127
*/
113-
MSIDErrorInvalidState = -52501,
128+
MSIDErrorInteractiveSessionAlreadyRunning = -51622,
114129

115-
MSIDErrorCodeFirst = MSIDErrorInternal,
116-
MSIDErrorCodeLast = MSIDErrorInvalidState
130+
// Embedded webview has failed to find a view controller to display web contents
131+
MSIDErrorNoMainViewController = - 51631,
117132
};
118133

119134
extern NSError *MSIDCreateError(NSString *domain, NSInteger code, NSString *errorDescription, NSString *oauthError, NSString *subError, NSError *underlyingError, NSUUID *correlationId, NSDictionary *additionalUserInfo);
120135

121136
extern MSIDErrorCode MSIDErrorCodeForOAuthError(NSString *oauthError, MSIDErrorCode defaultCode);
137+
138+
extern NSDictionary<NSString *, NSArray *> *MSIDErrorDomainsAndCodes(void);
139+

IdentityCore/src/MSIDError.m

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,58 @@ MSIDErrorCode MSIDErrorCodeForOAuthError(NSString *oauthError, MSIDErrorCode def
5252
{
5353
if (oauthError && [oauthError caseInsensitiveCompare:@"invalid_request"] == NSOrderedSame)
5454
{
55-
return MSIDErrorInvalidRequest;
55+
return MSIDErrorServerInvalidRequest;
5656
}
5757
if (oauthError && [oauthError caseInsensitiveCompare:@"invalid_client"] == NSOrderedSame)
5858
{
59-
return MSIDErrorInvalidClient;
59+
return MSIDErrorServerInvalidClient;
6060
}
6161
if (oauthError && [oauthError caseInsensitiveCompare:@"invalid_scope"] == NSOrderedSame)
6262
{
63-
return MSIDErrorInvalidScope;
63+
return MSIDErrorServerInvalidScope;
6464
}
6565
if (oauthError && [oauthError caseInsensitiveCompare:@"invalid_grant"] == NSOrderedSame)
6666
{
67-
return MSIDErrorInvalidGrant;
67+
return MSIDErrorServerInvalidGrant;
6868
}
6969

7070
return defaultCode;
7171
}
72+
73+
NSDictionary* MSIDErrorDomainsAndCodes()
74+
{
75+
return @{ MSIDErrorDomain : @[// General Errors
76+
@(MSIDErrorInternal),
77+
@(MSIDErrorInvalidInternalParameter),
78+
@(MSIDErrorInvalidDeveloperParameter),
79+
@(MSIDErrorUnsupportedFunctionality),
80+
81+
// Cache Errors
82+
@(MSIDErrorCacheMultipleUsers),
83+
@(MSIDErrorCacheBadFormat),
84+
85+
// Authority Validation Errors
86+
@(MSIDErrorAuthorityValidation),
87+
88+
// Interactive flow errors
89+
@(MSIDErrorAuthorizationFailed),
90+
@(MSIDErrorUserCancel),
91+
@(MSIDErrorSessionCanceledProgrammatically),
92+
@(MSIDErrorInteractiveSessionStartFailure),
93+
@(MSIDErrorInteractiveSessionAlreadyRunning),
94+
@(MSIDErrorNoMainViewController)
95+
],
96+
MSIDOAuthErrorDomain : @[// Server Errors
97+
@(MSIDErrorInteractionRequired),
98+
@(MSIDErrorServerOauth),
99+
@(MSIDErrorServerInvalidResponse),
100+
@(MSIDErrorServerRefreshTokenRejected),
101+
@(MSIDErrorServerInvalidRequest),
102+
@(MSIDErrorServerInvalidClient),
103+
@(MSIDErrorServerInvalidGrant),
104+
@(MSIDErrorServerInvalidScope),
105+
@(MSIDErrorServerInvalidState),
106+
@(MSIDErrorServerNonHttpsRedirect)
107+
]
108+
};
109+
}

IdentityCore/src/oauth2/MSIDTokenResponse.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ - (MSIDAccountType)accountType
101101

102102
- (MSIDErrorCode)oauthErrorCode
103103
{
104-
return MSIDErrorCodeForOAuthError(self.error, MSIDErrorInteractionRequired);
104+
return MSIDErrorCodeForOAuthError(self.error, MSIDErrorServerOauth);
105105
}
106106

107107
- (NSDictionary *)additionalServerInfo

IdentityCore/src/oauth2/MSIDWebviewFactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// Webviews creation
3535
- (MSIDWebviewSession *)embeddedWebviewSessionFromConfiguration:(MSIDWebviewConfiguration *)configuration customWebview:(WKWebView *)webview context:(id<MSIDRequestContext>)context;
3636

37-
#if TARGET_OS_IPHONE
37+
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
3838
- (MSIDWebviewSession *)systemWebviewSessionFromConfiguration:(MSIDWebviewConfiguration *)configuration context:(id<MSIDRequestContext>)context;
3939
#endif
4040

IdentityCore/src/oauth2/MSIDWebviewFactory.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ - (MSIDWebviewSession *)embeddedWebviewSessionFromConfiguration:(MSIDWebviewConf
5555
return session;
5656
}
5757

58-
#if TARGET_OS_IPHONE
58+
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
5959
- (MSIDWebviewSession *)systemWebviewSessionFromConfiguration:(MSIDWebviewConfiguration *)configuration context:(id<MSIDRequestContext>)context
6060
{
6161
NSString *state = [self generateStateValue];
@@ -180,7 +180,7 @@ - (BOOL)verifyRequestState:(NSString *)requestState
180180
if (error)
181181
{
182182
*error = MSIDCreateError(MSIDOAuthErrorDomain,
183-
MSIDErrorInvalidState,
183+
MSIDErrorServerInvalidState,
184184
[NSString stringWithFormat:@"Missing or invalid state returned state: %@", stateReceived],
185185
nil, nil, nil, nil, nil);
186186
}

IdentityCore/src/webview/MSIDWebviewAuthorization.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,18 @@ typedef void (^MSIDWebviewAuthCompletionHandler)(MSIDWebviewResponse *response,
5151
context:(id<MSIDRequestContext>)context
5252
completionHandler:(MSIDWebviewAuthCompletionHandler)completionHandler;
5353

54-
#if TARGET_OS_IPHONE
54+
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
5555
+ (void)startSystemWebviewWebviewAuthWithConfiguration:(MSIDWebviewConfiguration *)configuration
5656
oauth2Factory:(MSIDOauth2Factory *)oauth2Factory
5757
context:(id<MSIDRequestContext>)context
5858
completionHandler:(MSIDWebviewAuthCompletionHandler)completionHandler;
5959
#endif
6060

61+
6162
+ (BOOL)setCurrentSession:(MSIDWebviewSession *)session;
6263
+ (void)cancelCurrentSession;
6364

64-
#if TARGET_OS_IPHONE
65+
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
6566
// This is for system webview auth session on iOS 10 - Thus, a SafariViewController
6667
+ (BOOL)handleURLResponseForSystemWebviewController:(NSURL *)url;
6768
#endif

IdentityCore/src/webview/MSIDWebviewAuthorization.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ + (void)startEmbeddedWebviewWebviewAuthWithConfiguration:(MSIDWebviewConfigurati
6363
[self startSession:session context:context completionHandler:completionHandler];
6464
}
6565

66-
#if TARGET_OS_IPHONE
66+
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
6767
+ (void)startSystemWebviewWebviewAuthWithConfiguration:(MSIDWebviewConfiguration *)configuration
6868
oauth2Factory:(MSIDOauth2Factory *)oauth2Factory
6969
context:(id<MSIDRequestContext>)context
@@ -83,7 +83,7 @@ + (void)startSession:(MSIDWebviewSession *)session
8383
// check session nil
8484
if (!session)
8585
{
86-
NSError *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInvalidRequest, @"Interactive session failed to create.", nil, nil, nil, context.correlationId, nil);
86+
NSError *error = MSIDCreateError(MSIDErrorDomain, MSIDErrorInternal, @"Interactive session failed to create.", nil, nil, nil, context.correlationId, nil);
8787
completionHandler(nil, error);
8888
return;
8989
}
@@ -169,9 +169,9 @@ + (void)cancelCurrentSession
169169
}
170170
}
171171

172+
#if TARGET_OS_IPHONE && !MSID_EXCLUDE_SYSTEMWV
172173
+ (BOOL)handleURLResponseForSystemWebviewController:(NSURL *)url;
173174
{
174-
#if TARGET_OS_IPHONE
175175
@synchronized([MSIDWebviewAuthorization class])
176176
{
177177
if (s_currentSession &&
@@ -180,9 +180,8 @@ + (BOOL)handleURLResponseForSystemWebviewController:(NSURL *)url;
180180
return [((MSIDSystemWebviewController *)s_currentSession.webviewController) handleURLResponseForSafariViewController:url];
181181
}
182182
}
183-
#endif
184183
return NO;
185184
}
186-
185+
#endif
187186

188187
@end

0 commit comments

Comments
 (0)