TF-624 Implement get token oidc on browser

This commit is contained in:
dab246
2022-06-07 20:09:04 +07:00
committed by Dat H. Pham
parent abc7e3da9d
commit 261b6a5870
7 changed files with 91 additions and 5 deletions
@@ -16,7 +16,7 @@ class OidcConfigurationCacheManager {
} else {
return OIDCConfiguration(
authority: authority,
clientId: OIDCConstant.mobileOidcClientId,
clientId: OIDCConstant.clientId,
scopes: OIDCConstant.oidcScope);
}
}
@@ -1,7 +1,9 @@
import 'package:core/utils/app_logger.dart';
import 'package:get/get.dart';
import 'package:tmail_ui_user/features/login/data/extensions/authentication_token_extension.dart';
import 'package:tmail_ui_user/features/login/data/network/config/oidc_constant.dart';
import 'package:tmail_ui_user/features/login/domain/exceptions/authentication_exception.dart';
import 'package:universal_html/html.dart' as html;
import 'package:tmail_ui_user/features/login/data/network/authentication_client/authentication_client_base.dart';
import 'package:flutter_appauth_platform_interface/flutter_appauth_platform_interface.dart';
@@ -20,7 +22,25 @@ class AuthenticationClientWeb implements AuthenticationClientBase {
@override
Future<TokenOIDC> getTokenOIDC(String clientId, String redirectUrl,
String discoveryUrl, List<String> scopes) async {
throw UnimplementedError();
final authorizationTokenResponse = await _appAuthWeb.authorizeAndExchangeCode(AuthorizationTokenRequest(
clientId,
redirectUrl,
discoveryUrl: discoveryUrl,
scopes: scopes,
preferEphemeralSession: true));
log('AuthClientMobile::getTokenOIDC(): token: ${authorizationTokenResponse?.accessToken}');
if (authorizationTokenResponse != null) {
final tokenOIDC = authorizationTokenResponse.toTokenOIDC();
if (tokenOIDC.isTokenValid()) {
return tokenOIDC;
} else {
throw AccessTokenInvalidException();
}
} else {
throw NotFoundAccessTokenException();
}
}
@override