TF-624 Check and get oidc configuration on browser

This commit is contained in:
dab246
2022-06-07 18:09:32 +07:00
committed by Dat H. Pham
parent 9092e30b96
commit 217a3ccc9e
6 changed files with 80 additions and 3 deletions
@@ -37,6 +37,8 @@ abstract class BaseLoginView extends GetWidget<LoginController> {
return AppLocalizations.of(context).requiredEmail;
} else if (failure is LoginMissPasswordAction) {
return AppLocalizations.of(context).requiredPassword;
} else if (failure is LoginSSONotAvailableAction) {
return AppLocalizations.of(context).ssoNotAvailable;
} else if (failure is GetOIDCConfigurationFailure
|| failure is LoginCanNotVerifySSOConfigurationAction) {
return AppLocalizations.of(context).canNotVerifySSOConfiguration;
@@ -123,6 +123,28 @@ class LoginController extends GetxController {
}
}
void handleSSOPressed() async {
final baseUri = _parseUri(AppConfig.baseUrl);
if (baseUri != null) {
log('LoginController::handleSSOPressed(): baseUri: ${baseUri.toString()}');
loginState.value = LoginState(Right(LoginLoadingAction()));
await _checkOIDCIsAvailableInteractor
.execute(OIDCRequest(baseUrl: baseUri.toString(), resourceUrl: baseUri.origin))
.then((response) => response.fold(
(failure) => loginState.value = LoginState(Left(LoginSSONotAvailableAction())),
(success) {
if (success is CheckOIDCIsAvailableSuccess) {
loginState.value = LoginState(Right(success));
_oidcResponse = success.oidcResponse;
_getOIDCConfiguration();
} else {
loginState.value = LoginState(Left(LoginSSONotAvailableAction()));
}
}));
}
}
void _getOIDCConfiguration() async {
loginState.value = LoginState(Right(LoginLoadingAction()));
if (_oidcResponse != null) {
@@ -46,7 +46,8 @@ class LoginView extends BaseLoginView {
),
Obx(() => buildLoginMessage(context, loginController.loginState.value)),
buildInputCredentialForm(context),
buildLoginButton(context)
buildLoginButton(context),
buildSSOButton(context),
],
)
),
@@ -161,7 +162,8 @@ class LoginView extends BaseLoginView {
),
Obx(() => buildLoginMessage(context, loginController.loginState.value)),
buildInputCredentialForm(context),
buildLoginButton(context)
buildLoginButton(context),
buildSSOButton(context),
],
)
)
@@ -198,4 +200,28 @@ class LoginView extends BaseLoginView {
]
);
}
Widget buildSSOButton(BuildContext context) {
return Container(
margin: const EdgeInsets.only(bottom: 16, left: 24, right: 24),
width: responsiveUtils.getDeviceWidth(context),height: 48,
child: ElevatedButton(
key: const Key('ssoSubmitForm'),
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) => Colors.white),
backgroundColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) => AppColor.textFieldErrorBorderColor),
shape: MaterialStateProperty.all(RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: const BorderSide(width: 0, color: AppColor.textFieldErrorBorderColor)
))
),
child: Text(AppLocalizations.of(context).singleSignOn,
style: const TextStyle(fontSize: 16, color: Colors.white)
),
onPressed: () {
loginController.handleSSOPressed();
}
)
);
}
}
@@ -53,4 +53,9 @@ class LoginCanNotVerifySSOConfigurationAction extends Failure {
class LoginCanNotGetTokenAction extends Failure {
@override
List<Object?> get props => [];
}
class LoginSSONotAvailableAction extends Failure {
@override
List<Object?> get props => [];
}
+13 -1
View File
@@ -1,5 +1,5 @@
{
"@@last_modified": "2022-06-01T17:23:21.677245",
"@@last_modified": "2022-06-06T13:32:00.583993",
"initializing_data": "Initializing data...",
"@initializing_data": {
"type": "text",
@@ -1399,5 +1399,17 @@
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"singleSignOn": "Single Sign-On",
"@singleSignOn": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
},
"ssoNotAvailable": "Single sign-on (SSO) is not available",
"@ssoNotAvailable": {
"type": "text",
"placeholders_order": [],
"placeholders": {}
}
}
@@ -1431,4 +1431,14 @@ class AppLocalizations {
'All mailboxes',
name: 'allMailboxes');
}
String get singleSignOn {
return Intl.message('Single Sign-On',
name: 'singleSignOn');
}
String get ssoNotAvailable {
return Intl.message('Single sign-on (SSO) is not available',
name: 'ssoNotAvailable');
}
}