fix: Add log trace to send log to Sentry and print to web console for validate refresh token
This commit is contained in:
@@ -81,14 +81,18 @@ void _internalLog(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (shouldSentry) {
|
if (shouldSentry) {
|
||||||
unawaited(
|
if (level == Level.trace) {
|
||||||
SentryManager.instance.captureException(
|
SentryManager.instance.captureMessage(rawMessage, extras: extras);
|
||||||
exception ?? rawMessage,
|
} else {
|
||||||
stackTrace: stackTrace,
|
unawaited(
|
||||||
message: rawMessage,
|
SentryManager.instance.captureException(
|
||||||
extras: extras,
|
exception ?? rawMessage,
|
||||||
),
|
stackTrace: stackTrace,
|
||||||
);
|
message: rawMessage,
|
||||||
|
extras: extras,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +136,9 @@ void _printWebConsole(Level level, String value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _shouldReportToSentry(Level level) {
|
bool _shouldReportToSentry(Level level) {
|
||||||
return level == Level.error || level == Level.critical;
|
return level == Level.error ||
|
||||||
|
level == Level.critical ||
|
||||||
|
level == Level.trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
void logError(
|
void logError(
|
||||||
|
|||||||
@@ -217,25 +217,56 @@ class AuthorizationInterceptors extends QueuedInterceptorsWrapper {
|
|||||||
|
|
||||||
bool _isRefreshTokenNotEmpty(TokenOIDC? tokenOIDC) => tokenOIDC?.refreshToken.isNotEmpty == true;
|
bool _isRefreshTokenNotEmpty(TokenOIDC? tokenOIDC) => tokenOIDC?.refreshToken.isNotEmpty == true;
|
||||||
|
|
||||||
bool validateToRefreshToken({
|
bool validateToRefreshToken(
|
||||||
required int? responseStatusCode,
|
{required int? responseStatusCode, required TokenOIDC? tokenOIDC}) {
|
||||||
required TokenOIDC? tokenOIDC
|
final isStatusCode401 = responseStatusCode == 401;
|
||||||
}) {
|
final isLoginWithOIDC = _isAuthenticationOidcValid();
|
||||||
return responseStatusCode == 401
|
final hasAccessToken = _isTokenNotEmpty(tokenOIDC);
|
||||||
&& _isAuthenticationOidcValid()
|
final hasRefreshToken = _isRefreshTokenNotEmpty(tokenOIDC);
|
||||||
&& _isTokenNotEmpty(tokenOIDC)
|
final isExpired = _isTokenExpired(tokenOIDC);
|
||||||
&& _isRefreshTokenNotEmpty(tokenOIDC)
|
|
||||||
&& _isTokenExpired(tokenOIDC);
|
final canProceedRefresh = isStatusCode401 &&
|
||||||
|
isLoginWithOIDC &&
|
||||||
|
hasAccessToken &&
|
||||||
|
hasRefreshToken &&
|
||||||
|
isExpired;
|
||||||
|
|
||||||
|
logTrace(
|
||||||
|
'AuthorizationInterceptors::validateToRefreshToken: '
|
||||||
|
'isStatusCode401 = $isStatusCode401 | '
|
||||||
|
'isLoginWithOIDC = $isLoginWithOIDC | '
|
||||||
|
'hasAccessToken = $hasAccessToken | '
|
||||||
|
'hasRefreshToken = $hasRefreshToken | '
|
||||||
|
'isExpired = $isExpired | '
|
||||||
|
'canProceedRefresh = $canProceedRefresh',
|
||||||
|
webConsoleEnabled: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
return canProceedRefresh;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool validateToRetryTheRequestWithNewToken({
|
bool validateToRetryTheRequestWithNewToken(
|
||||||
required String? authHeader,
|
{required String? authHeader, required TokenOIDC? tokenOIDC}) {
|
||||||
required TokenOIDC? tokenOIDC
|
final hasAuthHeader = authHeader != null;
|
||||||
}) {
|
final hasAccessToken = _isTokenNotEmpty(tokenOIDC);
|
||||||
return authHeader != null
|
final isTokenStillValid = !_isTokenExpired(tokenOIDC);
|
||||||
&& _isTokenNotEmpty(tokenOIDC)
|
final isTokenUpdated =
|
||||||
&& !_isTokenExpired(tokenOIDC)
|
tokenOIDC != null && authHeader?.contains(tokenOIDC.token) != true;
|
||||||
&& !authHeader.contains(tokenOIDC!.token);
|
|
||||||
|
final shouldRetry =
|
||||||
|
hasAuthHeader && hasAccessToken && isTokenStillValid && isTokenUpdated;
|
||||||
|
|
||||||
|
logTrace(
|
||||||
|
'AuthorizationInterceptors::validateToRetryWithNewToken: '
|
||||||
|
'hasHeader = $hasAuthHeader | '
|
||||||
|
'hasAccessToken = $hasAccessToken | '
|
||||||
|
'isTokenValid = $isTokenStillValid | '
|
||||||
|
'isNewToken = $isTokenUpdated | '
|
||||||
|
'shouldRetry = $shouldRetry',
|
||||||
|
webConsoleEnabled: true,
|
||||||
|
);
|
||||||
|
|
||||||
|
return shouldRetry;
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getAuthorizationAsBasicHeader(String? authorization) => 'Basic $authorization';
|
String _getAuthorizationAsBasicHeader(String? authorization) => 'Basic $authorization';
|
||||||
|
|||||||
Reference in New Issue
Block a user