Commit 547201c8 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Fix bug that wasn't showing the login options for the first time.

parent a8ce982a
...@@ -87,7 +87,7 @@ fun newInstance( ...@@ -87,7 +87,7 @@ fun newInstance(
deepLinkInfo: LoginDeepLinkInfo? = null deepLinkInfo: LoginDeepLinkInfo? = null
): Fragment { ): Fragment {
return LoginOptionsFragment().apply { return LoginOptionsFragment().apply {
arguments = Bundle(19).apply { arguments = Bundle(23).apply {
putString(SERVER_NAME, serverName) putString(SERVER_NAME, serverName)
putString(STATE, state) putString(STATE, state)
putString(FACEBOOK_OAUTH_URL, facebookOauthUrl) putString(FACEBOOK_OAUTH_URL, facebookOauthUrl)
......
...@@ -117,175 +117,173 @@ abstract class CheckServerPresenter constructor( ...@@ -117,175 +117,173 @@ abstract class CheckServerPresenter constructor(
} }
internal suspend fun checkEnabledAccounts(serverUrl: String) { internal suspend fun checkEnabledAccounts(serverUrl: String) {
launchUI(strategy) { try {
try { val services = retryIO("settingsOauth()") {
val services = retryIO("settingsOauth()") { client.settingsOauth().services
client.settingsOauth().services }
}
if (services.isNotEmpty()) { if (services.isNotEmpty()) {
state = OauthHelper.getState() state = OauthHelper.getState()
// OAuth accounts. // OAuth accounts.
if (settings.isFacebookAuthenticationEnabled()) { if (settings.isFacebookAuthenticationEnabled()) {
getServiceMap(services, SERVICE_NAME_FACEBOOK)?.let { serviceMap -> getServiceMap(services, SERVICE_NAME_FACEBOOK)?.let { serviceMap ->
getOauthClientId(serviceMap)?.let { clientId -> getOauthClientId(serviceMap)?.let { clientId ->
facebookOauthUrl = facebookOauthUrl =
OauthHelper.getFacebookOauthUrl(clientId, serverUrl, state) OauthHelper.getFacebookOauthUrl(clientId, serverUrl, state)
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
}
if (settings.isGithubAuthenticationEnabled()) { if (settings.isGithubAuthenticationEnabled()) {
getServiceMap(services, SERVICE_NAME_GITHUB)?.let { serviceMap -> getServiceMap(services, SERVICE_NAME_GITHUB)?.let { serviceMap ->
getOauthClientId(serviceMap)?.let { clientId -> getOauthClientId(serviceMap)?.let { clientId ->
githubOauthUrl = githubOauthUrl =
OauthHelper.getGithubOauthUrl(clientId, state) OauthHelper.getGithubOauthUrl(clientId, state)
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
}
if (settings.isGoogleAuthenticationEnabled()) { if (settings.isGoogleAuthenticationEnabled()) {
getServiceMap(services, SERVICE_NAME_GOOGLE)?.let { serviceMap -> getServiceMap(services, SERVICE_NAME_GOOGLE)?.let { serviceMap ->
getOauthClientId(serviceMap)?.let { clientId -> getOauthClientId(serviceMap)?.let { clientId ->
googleOauthUrl = googleOauthUrl =
OauthHelper.getGoogleOauthUrl(clientId, serverUrl, state) OauthHelper.getGoogleOauthUrl(clientId, serverUrl, state)
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
}
if (settings.isLinkedinAuthenticationEnabled()) { if (settings.isLinkedinAuthenticationEnabled()) {
getServiceMap(services, SERVICE_NAME_LINKEDIN)?.let { serviceMap -> getServiceMap(services, SERVICE_NAME_LINKEDIN)?.let { serviceMap ->
getOauthClientId(serviceMap)?.let { clientId -> getOauthClientId(serviceMap)?.let { clientId ->
linkedinOauthUrl = linkedinOauthUrl =
OauthHelper.getLinkedinOauthUrl(clientId, serverUrl, state) OauthHelper.getLinkedinOauthUrl(clientId, serverUrl, state)
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
}
if (settings.isGitlabAuthenticationEnabled()) { if (settings.isGitlabAuthenticationEnabled()) {
getServiceMap(services, SERVICE_NAME_GILAB)?.let { serviceMap -> getServiceMap(services, SERVICE_NAME_GILAB)?.let { serviceMap ->
getOauthClientId(serviceMap)?.let { clientId -> getOauthClientId(serviceMap)?.let { clientId ->
gitlabOauthUrl = if (settings.gitlabUrl() != null) { gitlabOauthUrl = if (settings.gitlabUrl() != null) {
OauthHelper.getGitlabOauthUrl( OauthHelper.getGitlabOauthUrl(
host = settings.gitlabUrl(), host = settings.gitlabUrl(),
clientId = clientId, clientId = clientId,
serverUrl = serverUrl, serverUrl = serverUrl,
state = state state = state
) )
} else { } else {
OauthHelper.getGitlabOauthUrl( OauthHelper.getGitlabOauthUrl(
clientId = clientId, clientId = clientId,
serverUrl = serverUrl, serverUrl = serverUrl,
state = state state = state
) )
}
totalSocialAccountsEnabled++
} }
totalSocialAccountsEnabled++
} }
} }
}
if (settings.isWordpressAuthenticationEnabled()) { if (settings.isWordpressAuthenticationEnabled()) {
getServiceMap(services, SERVICE_NAME_WORDPRESS)?.let { serviceMap -> getServiceMap(services, SERVICE_NAME_WORDPRESS)?.let { serviceMap ->
getOauthClientId(serviceMap)?.let { clientId -> getOauthClientId(serviceMap)?.let { clientId ->
wordpressOauthUrl = wordpressOauthUrl =
if (settings.wordpressUrl().isNullOrEmpty()) { if (settings.wordpressUrl().isNullOrEmpty()) {
OauthHelper.getWordpressComOauthUrl( OauthHelper.getWordpressComOauthUrl(
clientId, clientId,
serverUrl, serverUrl,
state state
) )
} else { } else {
OauthHelper.getWordpressCustomOauthUrl( OauthHelper.getWordpressCustomOauthUrl(
getCustomOauthHost(serviceMap) getCustomOauthHost(serviceMap)
?: "https://public-api.wordpress.com", ?: "https://public-api.wordpress.com",
getCustomOauthAuthorizePath(serviceMap) getCustomOauthAuthorizePath(serviceMap)
?: "/oauth/authorize", ?: "/oauth/authorize",
clientId, clientId,
serverUrl, serverUrl,
SERVICE_NAME_WORDPRESS, SERVICE_NAME_WORDPRESS,
state, state,
getCustomOauthScope(serviceMap) ?: "openid" getCustomOauthScope(serviceMap) ?: "openid"
) )
} }
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
}
// CAS account. // CAS account.
if (settings.isCasAuthenticationEnabled()) { if (settings.isCasAuthenticationEnabled()) {
casToken = generateRandomString(17) casToken = generateRandomString(17)
casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString()) casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
} }
// Custom OAuth account. // Custom OAuth account.
getCustomOauthServices(services).let { getCustomOauthServices(services).let {
for (serviceMap in it) { for (serviceMap in it) {
customOauthServiceName = getCustomOauthServiceName(serviceMap) customOauthServiceName = getCustomOauthServiceName(serviceMap)
val host = getCustomOauthHost(serviceMap) val host = getCustomOauthHost(serviceMap)
val authorizePath = getCustomOauthAuthorizePath(serviceMap) val authorizePath = getCustomOauthAuthorizePath(serviceMap)
val clientId = getOauthClientId(serviceMap) val clientId = getOauthClientId(serviceMap)
val scope = getCustomOauthScope(serviceMap) val scope = getCustomOauthScope(serviceMap)
val serviceNameTextColor = val serviceNameTextColor =
getServiceNameColorForCustomOauthOrSaml(serviceMap) getServiceNameColorForCustomOauthOrSaml(serviceMap)
val serviceButtonColor = getServiceButtonColor(serviceMap) val serviceButtonColor = getServiceButtonColor(serviceMap)
if (customOauthServiceName != null && if (customOauthServiceName != null &&
host != null && host != null &&
authorizePath != null && authorizePath != null &&
clientId != null && clientId != null &&
scope != null && scope != null &&
serviceNameTextColor != null && serviceNameTextColor != null &&
serviceButtonColor != null serviceButtonColor != null
) { ) {
customOauthUrl = OauthHelper.getCustomOauthUrl( customOauthUrl = OauthHelper.getCustomOauthUrl(
host, host,
authorizePath, authorizePath,
clientId, clientId,
serverUrl, serverUrl,
customOauthServiceName.toString(), customOauthServiceName.toString(),
state, state,
scope scope
) )
customOauthServiceNameTextColor = serviceNameTextColor customOauthServiceNameTextColor = serviceNameTextColor
customOauthServiceButtonColor = serviceButtonColor customOauthServiceButtonColor = serviceButtonColor
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
}
// SAML account. // SAML account.
getSamlServices(services).let { getSamlServices(services).let {
samlToken = generateRandomString(17) samlToken = generateRandomString(17)
for (serviceMap in it) { for (serviceMap in it) {
val provider = getSamlProvider(serviceMap) val provider = getSamlProvider(serviceMap)
samlServiceName = getSamlServiceName(serviceMap) samlServiceName = getSamlServiceName(serviceMap)
val serviceNameTextColor = val serviceNameTextColor =
getServiceNameColorForCustomOauthOrSaml(serviceMap) getServiceNameColorForCustomOauthOrSaml(serviceMap)
val serviceButtonColor = getServiceButtonColor(serviceMap) val serviceButtonColor = getServiceButtonColor(serviceMap)
if (provider != null && if (provider != null &&
samlServiceName != null && samlServiceName != null &&
serviceNameTextColor != null && serviceNameTextColor != null &&
serviceButtonColor != null serviceButtonColor != null
) { ) {
samlUrl = serverUrl.samlUrl(provider, samlToken.toString()) samlUrl = serverUrl.samlUrl(provider, samlToken.toString())
samlServiceNameTextColor = serviceNameTextColor samlServiceNameTextColor = serviceNameTextColor
samlServiceButtonColor = serviceButtonColor samlServiceButtonColor = serviceButtonColor
totalSocialAccountsEnabled++ totalSocialAccountsEnabled++
}
} }
} }
} }
} catch (exception: RocketChatException) {
Timber.e(exception)
} }
} catch (exception: RocketChatException) {
Timber.e(exception)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment