feat: add single sign on by saml#420
Conversation
|
Thanks for the pull request, @RawanMatar89! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
There was a problem hiding this comment.
detekt found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
|
@RawanMatar89 it looks like there are some failing tests and checks, can you have a look. We can review this when the checks are passing. I also want to make sure we ensure this work meshes will with this: @xitij2000 can you chime in here? |
I am currently unable to test the code or have a deeper look; however, I do see some overlap. #371 adds a web-browser based flow that will initiate an OAuth flow with the LMS, delegating the actual login mechanism to whatever IdPs are set up at the LMS including any SAML-based ones. So from what I understand, what this PR is doing is already possible using the existing code. |
@xitij2000 good note that what I was thinking of when I looked at your WebView code. For a background, the original work has been done in the iOS app and is already merged since July 2024: This PR has gone stale a bit due to the review process and our internal prioritizations. My recommendation is to keep the iOS and the Android in a very similar flow in regards to backend integration and YAML configurations. @e0d @volodymyr-chekyrta How do you recommend going on with this? |
Good question. I would like to see a similar approach and feature flags for both platforms. |
|
Plan for this PR:
This approach will help keep both the Android and iOS code versions in sync while maintaining any necessary improvements from Web base LMS Auth PR work. |
|
dears, This PR is now ready for review. |
|
Hi @openedx/openedx-mobile-maintainers! Would someone be able to please take a look at this? |
Friendly ping on this @openedx/openedx-mobile-maintainers |
|
@RawanMatar89, could you please resolve conflicts on this PR? We will take it to review. |
|
@RawanMatar89 another ping for the rebase and conflict fixing. This is still on our plate and we'll push for it to get merged. Thanks @mphilbrick211 and @volodymyr-chekyrta for reviving it. |
|
@volodymyr-chekyrta, @OmarIthawi |
IvanStepanok
left a comment
There was a problem hiding this comment.
I’m worried about the SSO login flow here. In SSOWebContentScreen we read cookies without null checks and immediately split them,
| } | ||
| if (state.isSSOLoginEnabled) { | ||
| Spacer(modifier = Modifier.height(18.dp)) | ||
| if (state.isLoginRegistrationFormEnabled) { |
| buttonWidth | ||
| .testTag("btn_sso") | ||
| .fillMaxWidth(), | ||
| text = stringResource(id = coreR.string.core_sso_sign_in), |
There was a problem hiding this comment.
We are ignoring SSO_BUTTON_TITLE parameter on config file here
| } | ||
|
|
||
| viewModel { (courseId: String?, infoType: String?, authCode: String) -> | ||
| val lang = Resources.getSystem().configuration.locales[0].language |
There was a problem hiding this comment.
lang is lowercased here but in
SSO_BUTTON_TITLE:
AR: "الدخول عبر SSO"
EN: "Sign in with SSO"
parameters are uppercased. Can’t check this because in current implementation we are ignoring SSO_BUTTON_TITLE
| fun ssoLogin(token: String) { | ||
| logEvent(AuthAnalyticsEvent.USER_SIGN_IN_CLICKED) | ||
|
|
||
|
|
There was a problem hiding this comment.
We need to add the same logic as on default Login where we have a clean calendar and synchronize FCM if users are changed.
| _uiState.update { it.copy(showProgress = true) } | ||
| viewModelScope.launch { | ||
| try { | ||
| interactor.ssoLogin("JWT $token") |
There was a problem hiding this comment.
I cant check this, but looks like we will return here duplicates of "JWT". Like "JWTJWT token1323231232".
| if (preferencesManager.accessToken.isBlank() || | ||
| preferencesManager.refreshToken.isBlank()){ | ||
| preferencesManager.accessToken = jwtToken | ||
| preferencesManager.refreshToken = jwtToken |
There was a problem hiding this comment.
Do we need to update accessTokenExpiresAt here?
|
@IvanStepanok, I think all issues resolved, could you please check |
| override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
| super.onViewCreated(view, savedInstanceState) | ||
| setFragmentResultListener("requestKey") { _, bundle -> | ||
| val token = bundle.getString("bundleKey") |
There was a problem hiding this comment.
Please move "requestKey" and "bundleKey" to companion object. Reuse it for SSOWebContentFragment.kt too
| fun ssoClicked(fragmentManager: FragmentManager) { | ||
| router.navigateToSSOWebContent( | ||
| fm = fragmentManager, | ||
| title = resourceManager.getString(org.openedx.core.R.string.core_sso_sign_in), |
There was a problem hiding this comment.
move org.openedx.core.R to imports
| onWebPageUpdated = { | ||
| val token = it | ||
| if (token.isNotEmpty()){ | ||
| setFragmentResult("requestKey", bundleOf("bundleKey" to token)) |
There was a problem hiding this comment.
use consts for "requestKey" and "bundleKey"
|
|
||
| SSO_BUTTON_TITLE: | ||
| AR: "الدخول عبر SSO" | ||
| EN: "Sign in with SSO" |
There was a problem hiding this comment.
I think for more consistency it would be better to set the strings in the resources strings.xml file
There was a problem hiding this comment.
How do you propose this to happen @PavloNetrebchuk? Given that there's more than one button in the same app which isn't very practical to maintain in the context of strings.xml.
There was a problem hiding this comment.
But we are showing only 1 button in 1 language at the same time. Could you describe this flow in more detail, I don't fully understand the reason for this decision
| var cookieValue: String? = "" | ||
| if (siteName != null && cookieName != null) { | ||
| val cookieManager = CookieManager.getInstance() | ||
| val cookies = cookieManager.getCookie(siteName) |
There was a problem hiding this comment.
If the request fails, the cookies will return null and the application will crash with a NullPointerException. We need to handle the error and display a message.
|
Issues resolved ✔️ 🙏🏻 |


Describtion:
as in iOS, we added a new button in sign in view named "Sign in with SSO" to be use for opening single sign on web view
TODO:
Screenshots: