Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error code & other related tasks refactoring #153

Merged
merged 21 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
59dedf2
revise error codes
unpluggedk Jun 18, 2018
5305f64
re-add codeFirst and last for boundary checks
unpluggedk Jun 18, 2018
1370486
address feedback
unpluggedk Jun 22, 2018
fb06c85
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
unpluggedk Jun 22, 2018
1a4a89f
update project file and error codes (MSAL tested)
unpluggedk Jun 23, 2018
79f415f
additional conditional checks for disabling system webview from
unpluggedk Jun 25, 2018
26fcc80
minor typo
unpluggedk Jun 25, 2018
d26da5a
additional conditionals to fix unit tests
unpluggedk Jun 25, 2018
258ce69
add conditional checker for importing additional xcconfig
unpluggedk Jun 25, 2018
f383235
separate authority validation failure from server error
unpluggedk Jun 25, 2018
abb22c7
Merge branch 'jak/error-coding' of https://github.com/AzureAD/microso…
unpluggedk Jun 25, 2018
92ec263
separate embedded webview cancel to user cancel and app cancel
unpluggedk Jun 25, 2018
f14de0e
report error at auth session cancellation programatically.
unpluggedk Jun 25, 2018
d49dd2e
fix error to have right domain
unpluggedk Jun 25, 2018
bbd6375
address more code refactoring
unpluggedk Jun 25, 2018
6b87210
minor fix after MSAL integration
unpluggedk Jun 26, 2018
3672f38
rework numbers for easier addition in future, and minor adjustment after
unpluggedk Jun 26, 2018
3117678
fix unit test
unpluggedk Jun 26, 2018
089ec9f
address comments
unpluggedk Jun 26, 2018
9acc5b8
Merge branch 'dev' of https://github.com/AzureAD/microsoft-authentica…
unpluggedk Jun 26, 2018
330fcd8
typo on MSIDErrorSessionCanceledProgramatically
unpluggedk Jun 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 64 additions & 46 deletions IdentityCore/src/MSIDError.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,77 +41,95 @@ extern NSString *MSIDKeychainErrorDomain;

typedef NS_ENUM(NSInteger, MSIDErrorCode)
{
/*! =================================================
General Errors (510xx, 511xx)
================================================= */
// General internal errors that do not fall into one of the specific type
// of an error described below.
MSIDErrorInternal = -51000,
MSIDErrorInvalidInternalParameter = -51001,

MSIDErrorInvalidDeveloperParameter = -51002,
MSIDErrorAmbiguousAuthority = -51003,
MSIDErrorInteractionRequired = -51004,
// Parameter errors
MSIDErrorInvalidInternalParameter = -51101,
MSIDErrorInvalidDeveloperParameter = -51102,

// Unsupported functionality
MSIDErrorUnsupportedFunctionality = -51199,

MSIDErrorCacheMultipleUsers = -51005,
/*!
=================================================
Cache Errors (512xx,
513xx - Keychain)
=================================================
*/

// Multiple users found in cache when one was intended
MSIDErrorCacheMultipleUsers = -51201,

/*!
MSID encounted an error when trying to store or retrieve items from
keychain. Inspect NSUnderlyingError from the userInfo dictionary for
more information about the specific error. Keychain error codes are
documented in Apple's <Security/SecBase.h> header file
*/
MSIDErrorTokenCacheItemFailure = -51006,
MSIDErrorWrapperCacheFailure = -51007,
MSIDErrorCacheBadFormat = -51008,
MSIDErrorCacheVersionMismatch = -51009,
MSIDErrorTokenCacheItemFailure = -51301,
MSIDErrorWrapperCacheFailure = -51302,
MSIDErrorCacheBadFormat = -51303,
MSIDErrorCacheVersionMismatch = -51304,

MSIDErrorServerInvalidResponse = -51010,
MSIDErrorDeveloperAuthorityValidation = -51011,
MSIDErrorServerRefreshTokenRejected = -51012,
MSIDErrorServerOauth = -51013,
MSIDErrorInvalidRequest = -51014,
MSIDErrorInvalidClient = -51015,
MSIDErrorInvalidGrant = -51016,
MSIDErrorInvalidScope = -51017,
MSIDErrorInvalidParameter = -51018,
/*!
=================================================
Server errors (514xx)
=================================================
*/
// Server returned a response indicating an OAuth error
MSIDErrorServerOauth = -51401,
// Server returned an invalid response
MSIDErrorServerInvalidResponse = -51402,
// Server returned a refresh token reject response
MSIDErrorServerRefreshTokenRejected = -51403,
// Other specific server response errors
MSIDErrorInvalidRequest = -51404,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should it also have "server" in it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

MSIDErrorInvalidClient = -51405,
MSIDErrorInvalidGrant = -51406,
MSIDErrorInvalidScope = -51407,

/*!
=================================================
Interactive flow errors (515xx)
=================================================
*/
/*!
The user or application failed to authenticate in the interactive flow.
Inspect MSALOAuthErrorKey and MSALErrorDescriptionKey in the userInfo
dictionary for more detailed information about the specific error.
*/
MSIDErrorAuthorizationFailed = -52020,
MSIDErrorAuthorizationFailed = -51510,

/*!
The state returned by the server does not match the state that was sent to
the server at the beginning of the authorization attempt.
*/
MSIDErrorInvalidState = -52501,
/*!
Interaction required errors occur because of a wide variety of errors
returned by the authentication service.
*/
MSIDErrorMismatchedUser = -52101,
MSIDErrorNoAuthorizationResponse = -52102,
MSIDErrorBadAuthorizationResponse = -52103,
// State verification has failed in the interactive flow.
MSIDErrorInvalidState = -51511,

// User has cancelled the interactive flow.
MSIDErrorUserCancel = -51512,

MSIDErrorUserCancel = -51019,
/*!
The authentication request was cancelled programmatically.
*/
MSIDErrorSessionCanceled = -51020,
// The interactive flow was cancelled programmatically.
MSIDErrorSessionCanceled = -51513,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can the error name "hint" that it was canceled programmatically?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


// Interactive authentication session failed to start.
MSIDErrorInteractiveSessionStartFailure = -51514,
/*!
An interactive authentication session is already running with the
SafariViewController visible. Another authentication session can not be
launched yet.
An interactive authentication session is already running.
Another authentication session can not be launched yet.
*/
MSIDErrorInteractiveSessionAlreadyRunning = -51021,
MSIDErrorInteractiveSessionAlreadyRunning = -51515,

/*!
An interactive authentication session failed to start.
=================================================
Boundaries - To be used to enumerate all codes
=================================================
*/
MSIDErrorInteractiveSessionStartFailure = -51022,

MSIDErrorUnsupportedFunctionality = -51018,

MSIDErrorCodeFirst = MSIDErrorInternal,
MSIDErrorCodeLast = MSIDErrorUnsupportedFunctionality
MSIDErrorCodeLast = MSIDErrorInteractiveSessionAlreadyRunning

};

extern NSError *MSIDCreateError(NSString *domain, NSInteger code, NSString *errorDescription, NSString *oauthError, NSString *subError, NSError *underlyingError, NSUUID *correlationId, NSDictionary *additionalUserInfo);
Expand Down
2 changes: 1 addition & 1 deletion IdentityCore/src/oauth2/MSIDTokenResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (MSIDAccountType)accountType

- (MSIDErrorCode)oauthErrorCode
{
return MSIDErrorCodeForOAuthError(self.error, MSIDErrorInteractionRequired);
return MSIDErrorCodeForOAuthError(self.error, MSIDErrorServerOauth);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the clients know to show UI on MSIDErrorServerOauth? I think the reason to have MSIDErrorInteractionRequired as default is so that client show UI in MSAL? Can we check what was MSAL and ADAL implementation before?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top level : Interaction required
Underlying : ServerOAuth

and double check converter in MSAL and ADAL

}

- (NSDictionary *)additionalServerInfo
Expand Down
5 changes: 4 additions & 1 deletion IdentityCore/src/webview/response/MSIDWebOAuth2Response.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ - (instancetype)initWithURL:(NSURL *)url
{
if (error)
{
*error = MSIDCreateError(MSIDOAuthErrorDomain, MSIDErrorInvalidParameter, @"Unexpected error has occured. There is no auth code nor an error", nil, nil, nil, context.correlationId, nil);
*error = MSIDCreateError(MSIDOAuthErrorDomain,
MSIDErrorServerInvalidResponse,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@"Unexpected error has occured. There is no auth code nor an error",
nil, nil, nil, context.correlationId, nil);
}
return nil;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ - (instancetype)initWithURL:(NSURL *)url
{
if (error)
{
*error = MSIDCreateError(MSIDOAuthErrorDomain, MSIDErrorInvalidParameter, @"WPJ response should have msauth as a scheme and wpj/broker as a host", nil, nil, nil, context.correlationId, nil);
*error = MSIDCreateError(MSIDOAuthErrorDomain,
MSIDErrorServerInvalidResponse,
@"WPJ response should have msauth as a scheme and wpj/broker as a host",
nil, nil, nil, context.correlationId, nil);
}
return nil;
}
Expand Down
5 changes: 4 additions & 1 deletion IdentityCore/src/webview/response/MSIDWebviewResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ - (instancetype)initWithURL:(NSURL *)url
if (!url)
{
if (error){
*error = MSIDCreateError(MSIDOAuthErrorDomain, MSIDErrorInvalidParameter, @"Trying to create a response with nil URL", nil, nil, nil, context.correlationId, nil);
*error = MSIDCreateError(MSIDOAuthErrorDomain,
MSIDErrorServerInvalidResponse,
@"Trying to create a response with nil URL",
nil, nil, nil, context.correlationId, nil);
}
return nil;
}
Expand Down
2 changes: 1 addition & 1 deletion IdentityCore/tests/MSIDWebOAuth2ResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (void)testInitWithParameters_whenNoAuthCodeAndNoError_shouldReturnNilAndInvali
NSError *error = nil;
XCTAssertNil([[MSIDWebOAuth2Response alloc] initWithURL:[NSURL URLWithString:@"https://contoso.com"]
context:nil error:&error]);
XCTAssertEqual(error.code, MSIDErrorInvalidParameter);
XCTAssertEqual(error.code, MSIDErrorServerInvalidResponse);
}

- (void)testInitWithParameters_whenAuthCode_shouldReturnAuthCode
Expand Down
2 changes: 1 addition & 1 deletion IdentityCore/tests/MSIDWebWPJResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ - (void)testInit_whenWrongScheme_shouldReturnNilWithError
XCTAssertNotNil(error);

XCTAssertEqualObjects(error.domain, MSIDOAuthErrorDomain);
XCTAssertEqual(error.code, MSIDErrorInvalidParameter);
XCTAssertEqual(error.code, MSIDErrorServerInvalidResponse);
}


Expand Down
2 changes: 1 addition & 1 deletion IdentityCore/tests/MSIDWebviewResponseTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (void)testInitWithURL_whenNilURL_shouldReturnNilAndError

XCTAssertNil(response);
XCTAssertNotNil(error);
XCTAssertEqual(error.code, MSIDErrorInvalidParameter);
XCTAssertEqual(error.code, MSIDErrorServerInvalidResponse);
}

- (void)testInitWithURL_whenURLWithParams_shouldReturnInstanceWithParams
Expand Down