Skip to content

Commit

Permalink
Unify log levels in Native Auth (#2184)
Browse files Browse the repository at this point in the history
* Unify log levels

* Update changelog
  • Loading branch information
diegojerezba authored Jun 19, 2024
1 parent 9603f0b commit ada3906
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.4.1]:
* Update Native Auth logging levels for improved clarity and consistency. #2184

## [1.4.0]:
* Add platform sequence param. #2192
* Native auth can now store multiple access tokens related to different resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,15 @@ extension MSALNativeAuthTokenController {
// If there is an account existing already in the cache, we remove it
try clearAccount(msidConfiguration: msidConfiguration, context: context)
} catch {
MSALLogger.log(level: .error, context: context, format: "Error clearing account \(error) (ignoring)")
MSALLogger.log(level: .warning, context: context, format: "Error clearing account \(error) (ignoring)")
}
do {
let result = try cacheAccessor.validateAndSaveTokensAndAccount(tokenResponse: tokenResponse,
configuration: msidConfiguration,
context: context)
return result
} catch {
MSALLogger.log(level: .error, context: context, format: "Error caching response: \(error) (ignoring)")
MSALLogger.log(level: .warning, context: context, format: "Error caching response: \(error) (ignoring)")
}
return nil
}
Expand All @@ -194,12 +194,12 @@ extension MSALNativeAuthTokenController {
context: context)
}
} else {
MSALLogger.log(level: .error,
MSALLogger.log(level: .warning,
context: context,
format: "Error creating MSIDAccountIdentifier out of MSALAccount (ignoring)")
}
} catch {
MSALLogger.log(level: .error, context: context, format: "Error clearing previous account (ignoring)")
MSALLogger.log(level: .warning, context: context, format: "Error clearing previous account (ignoring)")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ final class MSALNativeAuthResetPasswordController: MSALNativeAuthBaseController,
event: MSIDTelemetryAPIEvent?,
context: MSALNativeAuthRequestContext) async -> ResetPasswordStartControllerResponse {

MSALLogger.log(level: .verbose, context: context, format: "Finished resetpassword/start request")
MSALLogger.log(level: .info, context: context, format: "Finished resetpassword/start request")

switch response {
case .success(let continuationToken):
Expand Down Expand Up @@ -489,14 +489,14 @@ final class MSALNativeAuthResetPasswordController: MSALNativeAuthBaseController,
event: MSIDTelemetryAPIEvent?,
context: MSALNativeAuthRequestContext
) async -> ResetPasswordSubmitPasswordControllerResponse {
MSALLogger.log(level: .verbose, context: context, format: "Performing poll completion request")
MSALLogger.log(level: .info, context: context, format: "Performing poll completion request")

let pollCompletionResponse = await performPollCompletionRequest(
continuationToken: continuationToken,
context: context
)

MSALLogger.log(level: .verbose, context: context, format: "Handling poll completion response")
MSALLogger.log(level: .info, context: context, format: "Handling poll completion response")

return await handlePollCompletionResponse(
pollCompletionResponse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
func signIn(params: MSALNativeAuthSignInParameters) async -> SignInControllerResponse {
let eventId: MSALNativeAuthTelemetryApiId =
params.password == nil ? .telemetryApiIdSignInWithCodeStart : .telemetryApiIdSignInWithPasswordStart
MSALLogger.log(level: .verbose, context: params.context, format: "SignIn started")
MSALLogger.log(level: .info, context: params.context, format: "SignIn started")
let telemetryInfo = TelemetryInfo(
event: makeAndStartTelemetryEvent(id: eventId, context: params.context),
context: params.context
Expand All @@ -103,7 +103,7 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
scopes: [String]?,
context: MSALNativeAuthRequestContext
) async -> SignInAfterPreviousFlowControllerResponse {
MSALLogger.log(level: .verbose, context: context, format: "SignIn after previous flow started")
MSALLogger.log(level: .info, context: context, format: "SignIn after previous flow started")
let telemetryInfo = TelemetryInfo(
event: makeAndStartTelemetryEvent(id: .telemetryApiIdSignInAfterSignUp, context: context),
context: context
Expand Down Expand Up @@ -469,7 +469,7 @@ final class MSALNativeAuthSignInController: MSALNativeAuthTokenController, MSALN
let tokenResult = try cacheTokenResponse(tokenResponse, context: context, msidConfiguration: config)

if let userAccountResult = factory.makeUserAccountResult(tokenResult: tokenResult, context: context) {
MSALLogger.log(level: .verbose, context: context, format: "SignIn completed successfully")
MSALLogger.log(level: .info, context: context, format: "SignIn completed successfully")
telemetryInfo.event?.setUserInformation(tokenResult.account)
stopTelemetryEvent(telemetryInfo)
onSuccess(userAccountResult)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,12 @@ final class MSALNativeAuthSignUpController: MSALNativeAuthBaseController, MSALNa
)
return .init(.error(error: error, newState: state), correlationId: context.correlationId())
case .credentialRequired(let newContinuationToken, _):
MSALLogger.log(level: .verbose, context: context, format: "credential_required received in signup/continue request")
MSALLogger.log(level: .info, context: context, format: "credential_required received in signup/continue request")

let result = await performAndValidateChallengeRequest(continuationToken: newContinuationToken, context: context)
return handlePerformChallengeAfterContinueRequest(result, username: username, event: event, context: context)
case .attributesRequired(let newContinuationToken, let attributes, _):
MSALLogger.log(level: .verbose, context: context, format: "attributes_required received in signup/continue request: \(attributes)")
MSALLogger.log(level: .info, context: context, format: "attributes_required received in signup/continue request: \(attributes)")

let state = SignUpAttributesRequiredState(controller: self,
username: username,
Expand Down Expand Up @@ -561,7 +561,7 @@ final class MSALNativeAuthSignUpController: MSALNativeAuthBaseController, MSALNa

return .init(.error(error: error, newState: state), correlationId: context.correlationId())
case .attributesRequired(let newContinuationToken, let attributes, _):
MSALLogger.log(level: .verbose, context: context, format: "attributes_required received in signup/continue request: \(attributes)")
MSALLogger.log(level: .info, context: context, format: "attributes_required received in signup/continue request: \(attributes)")

let state = SignUpAttributesRequiredState(controller: self,
username: username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ final class MSALNativeAuthResetPasswordResponseValidator: MSALNativeAuthResetPas

private func handleChallengeError(_ error: Error, with context: MSIDRequestContext) -> MSALNativeAuthResetPasswordChallengeValidatedResponse {
guard let apiError = error as? MSALNativeAuthResetPasswordChallengeResponseError else {
MSALLogger.log(level: .info, context: context, format: "resetpassword/challenge: Unable to decode error response: \(error)")
MSALLogger.log(level: .error, context: context, format: "resetpassword/challenge: Unable to decode error response: \(error)")
return .unexpectedError(.init(errorDescription: MSALNativeAuthErrorMessage.unexpectedResponseBody))
}
if apiError.error == .unknown {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension SignInCodeRequiredState {

func submitCodeInternal(code: String) async -> MSALNativeAuthSignInControlling.SignInSubmitCodeControllerResponse {
let context = MSALNativeAuthRequestContext(correlationId: correlationId)
MSALLogger.log(level: .verbose, context: context, format: "SignIn flow, code submitted")
MSALLogger.log(level: .info, context: context, format: "SignIn flow, code submitted")
guard inputValidator.isInputValid(code) else {
MSALLogger.log(level: .error, context: context, format: "SignIn flow, invalid code")
return .init(.error(error: VerifyCodeError(
Expand All @@ -42,7 +42,7 @@ extension SignInCodeRequiredState {

func resendCodeInternal() async -> MSALNativeAuthSignInControlling.SignInResendCodeControllerResponse {
let context = MSALNativeAuthRequestContext(correlationId: correlationId)
MSALLogger.log(level: .verbose, context: context, format: "SignIn flow, resend code requested")
MSALLogger.log(level: .info, context: context, format: "SignIn flow, resend code requested")

return await controller.resendCode(continuationToken: continuationToken, context: context, scopes: scopes)
}
Expand Down

0 comments on commit ada3906

Please sign in to comment.