Skip to content

Commit dbfcde7

Browse files
authored
Merge pull request RocketChat#1771 from RocketChat/fix/onboarding
[FIX] Fixes for Onboarding/Authentication
2 parents c9471b6 + 7132856 commit dbfcde7

File tree

5 files changed

+169
-178
lines changed

5 files changed

+169
-178
lines changed

app/src/main/java/chat/rocket/android/authentication/loginoptions/presentation/LoginOptionsPresenter.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,23 @@ class LoginOptionsPresenter @Inject constructor(
7272
credentialToken = oauthToken
7373
credentialSecret = oauthSecret
7474
loginMethod = AuthenticationEvent.AuthenticationWithOauth
75+
setupConnectionInfo(currentServer)
7576
doAuthentication(TYPE_LOGIN_OAUTH)
7677
}
7778

7879
fun authenticateWithCas(casToken: String) {
7980
setupConnectionInfo(currentServer)
8081
credentialToken = casToken
8182
loginMethod = AuthenticationEvent.AuthenticationWithCas
83+
setupConnectionInfo(currentServer)
8284
doAuthentication(TYPE_LOGIN_CAS)
8385
}
8486

8587
fun authenticateWithSaml(samlToken: String) {
8688
setupConnectionInfo(currentServer)
8789
credentialToken = samlToken
8890
loginMethod = AuthenticationEvent.AuthenticationWithSaml
91+
setupConnectionInfo(currentServer)
8992
doAuthentication(TYPE_LOGIN_SAML)
9093
}
9194

app/src/main/java/chat/rocket/android/authentication/loginoptions/ui/LoginOptionsFragment.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import android.view.View
99
import android.view.ViewGroup
1010
import android.widget.Button
1111
import android.widget.LinearLayout
12+
import androidx.appcompat.view.ContextThemeWrapper
1213
import androidx.core.view.isVisible
1314
import androidx.fragment.app.Fragment
1415
import chat.rocket.android.R
@@ -18,11 +19,7 @@ import chat.rocket.android.authentication.domain.model.LoginDeepLinkInfo
1819
import chat.rocket.android.authentication.loginoptions.presentation.LoginOptionsPresenter
1920
import chat.rocket.android.authentication.loginoptions.presentation.LoginOptionsView
2021
import chat.rocket.android.authentication.ui.AuthenticationActivity
21-
import chat.rocket.android.util.extensions.clearLightStatusBar
22-
import chat.rocket.android.util.extensions.inflate
23-
import chat.rocket.android.util.extensions.rotateBy
24-
import chat.rocket.android.util.extensions.showToast
25-
import chat.rocket.android.util.extensions.ui
22+
import chat.rocket.android.util.extensions.*
2623
import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_SECRET
2724
import chat.rocket.android.webview.oauth.ui.INTENT_OAUTH_CREDENTIAL_TOKEN
2825
import chat.rocket.android.webview.oauth.ui.oauthWebViewIntent
@@ -290,7 +287,6 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
290287
}
291288
}
292289

293-
294290
// OAuth Accounts.
295291
override fun enableLoginByFacebook() = enableAccountButton(button_facebook)
296292

@@ -337,8 +333,8 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
337333
buttonColor: Int
338334
) {
339335
val button = getCustomServiceButton(serviceName, serviceNameColor, buttonColor)
340-
accounts_container.addView(button)
341336
setupButtonListener(button, customOauthUrl, state, REQUEST_CODE_FOR_OAUTH)
337+
accounts_container.addView(button)
342338
}
343339

344340
// SAML account.
@@ -350,8 +346,8 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
350346
buttonColor: Int
351347
) {
352348
val button = getCustomServiceButton(serviceName, serviceNameColor, buttonColor)
353-
accounts_container.addView(button)
354349
setupButtonListener(button, samlUrl, samlToken, REQUEST_CODE_FOR_SAML)
350+
accounts_container.addView(button)
355351
}
356352

357353
override fun showAccountsView() {
@@ -487,7 +483,11 @@ class LoginOptionsFragment : Fragment(), LoginOptionsView {
487483
val marginTop = resources.getDimensionPixelSize(R.dimen.button_account_margin_top)
488484
params.setMargins(0, marginTop, 0, 0)
489485

490-
val button = Button(context)
486+
val button = Button(
487+
ContextThemeWrapper(context, R.style.Authentication_Button),
488+
null,
489+
R.style.Authentication_Button
490+
)
491491
button.layoutParams = params
492492
button.text = buttonText
493493
button.setTextColor(buttonTextColor)

app/src/main/java/chat/rocket/android/server/presentation/CheckServerPresenter.kt

Lines changed: 146 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -124,166 +124,174 @@ abstract class CheckServerPresenter constructor(
124124

125125
if (services.isNotEmpty()) {
126126
state = OauthHelper.getState()
127+
checkEnabledOauthAccounts(services, serverUrl)
128+
checkEnabledCasAccounts(serverUrl)
129+
checkEnabledCustomOauthAccounts(services, serverUrl)
130+
checkEnabledSamlAccounts(services, serverUrl)
131+
}
132+
} catch (exception: RocketChatException) {
133+
Timber.e(exception)
134+
}
135+
}
127136

128-
// OAuth accounts.
129-
if (settings.isFacebookAuthenticationEnabled()) {
130-
getServiceMap(services, SERVICE_NAME_FACEBOOK)?.let { serviceMap ->
131-
getOauthClientId(serviceMap)?.let { clientId ->
132-
facebookOauthUrl =
133-
OauthHelper.getFacebookOauthUrl(clientId, serverUrl, state)
134-
totalSocialAccountsEnabled++
135-
}
136-
}
137+
private fun checkEnabledOauthAccounts(services: List<Map<String,Any>>, serverUrl: String) {
138+
139+
if (settings.isFacebookAuthenticationEnabled()) {
140+
getServiceMap(services, SERVICE_NAME_FACEBOOK)?.let { serviceMap ->
141+
getOauthClientId(serviceMap)?.let { clientId ->
142+
facebookOauthUrl =
143+
OauthHelper.getFacebookOauthUrl(clientId, serverUrl, state)
144+
totalSocialAccountsEnabled++
137145
}
146+
}
147+
}
138148

139-
if (settings.isGithubAuthenticationEnabled()) {
140-
getServiceMap(services, SERVICE_NAME_GITHUB)?.let { serviceMap ->
141-
getOauthClientId(serviceMap)?.let { clientId ->
142-
githubOauthUrl =
143-
OauthHelper.getGithubOauthUrl(clientId, state)
144-
totalSocialAccountsEnabled++
145-
}
146-
}
149+
if (settings.isGithubAuthenticationEnabled()) {
150+
getServiceMap(services, SERVICE_NAME_GITHUB)?.let { serviceMap ->
151+
getOauthClientId(serviceMap)?.let { clientId ->
152+
githubOauthUrl =
153+
OauthHelper.getGithubOauthUrl(clientId, state)
154+
totalSocialAccountsEnabled++
147155
}
156+
}
157+
}
148158

149-
if (settings.isGoogleAuthenticationEnabled()) {
150-
getServiceMap(services, SERVICE_NAME_GOOGLE)?.let { serviceMap ->
151-
getOauthClientId(serviceMap)?.let { clientId ->
152-
googleOauthUrl =
153-
OauthHelper.getGoogleOauthUrl(clientId, serverUrl, state)
154-
totalSocialAccountsEnabled++
155-
}
156-
}
159+
if (settings.isGoogleAuthenticationEnabled()) {
160+
getServiceMap(services, SERVICE_NAME_GOOGLE)?.let { serviceMap ->
161+
getOauthClientId(serviceMap)?.let { clientId ->
162+
googleOauthUrl =
163+
OauthHelper.getGoogleOauthUrl(clientId, serverUrl, state)
164+
totalSocialAccountsEnabled++
157165
}
166+
}
167+
}
168+
169+
if (settings.isLinkedinAuthenticationEnabled()) {
170+
getServiceMap(services, SERVICE_NAME_LINKEDIN)?.let { serviceMap ->
171+
getOauthClientId(serviceMap)?.let { clientId ->
172+
linkedinOauthUrl =
173+
OauthHelper.getLinkedinOauthUrl(clientId, serverUrl, state)
174+
totalSocialAccountsEnabled++
175+
}
176+
}
177+
}
158178

159-
if (settings.isLinkedinAuthenticationEnabled()) {
160-
getServiceMap(services, SERVICE_NAME_LINKEDIN)?.let { serviceMap ->
161-
getOauthClientId(serviceMap)?.let { clientId ->
162-
linkedinOauthUrl =
163-
OauthHelper.getLinkedinOauthUrl(clientId, serverUrl, state)
164-
totalSocialAccountsEnabled++
165-
}
179+
if (settings.isGitlabAuthenticationEnabled()) {
180+
getServiceMap(services, SERVICE_NAME_GILAB)?.let { serviceMap ->
181+
getOauthClientId(serviceMap)?.let { clientId ->
182+
gitlabOauthUrl = if (settings.gitlabUrl() != null) {
183+
OauthHelper.getGitlabOauthUrl(
184+
host = settings.gitlabUrl(),
185+
clientId = clientId,
186+
serverUrl = serverUrl,
187+
state = state
188+
)
189+
} else {
190+
OauthHelper.getGitlabOauthUrl(
191+
clientId = clientId,
192+
serverUrl = serverUrl,
193+
state = state
194+
)
166195
}
196+
totalSocialAccountsEnabled++
167197
}
198+
}
199+
}
168200

169-
if (settings.isGitlabAuthenticationEnabled()) {
170-
getServiceMap(services, SERVICE_NAME_GILAB)?.let { serviceMap ->
171-
getOauthClientId(serviceMap)?.let { clientId ->
172-
gitlabOauthUrl = if (settings.gitlabUrl() != null) {
173-
OauthHelper.getGitlabOauthUrl(
174-
host = settings.gitlabUrl(),
175-
clientId = clientId,
176-
serverUrl = serverUrl,
177-
state = state
201+
if (settings.isWordpressAuthenticationEnabled()) {
202+
getServiceMap(services, SERVICE_NAME_WORDPRESS)?.let { serviceMap ->
203+
getOauthClientId(serviceMap)?.let { clientId ->
204+
wordpressOauthUrl =
205+
if (settings.wordpressUrl().isNullOrEmpty()) {
206+
OauthHelper.getWordpressComOauthUrl(
207+
clientId,
208+
serverUrl,
209+
state
178210
)
179211
} else {
180-
OauthHelper.getGitlabOauthUrl(
181-
clientId = clientId,
182-
serverUrl = serverUrl,
183-
state = state
212+
OauthHelper.getWordpressCustomOauthUrl(
213+
getCustomOauthHost(serviceMap)
214+
?: "https://public-api.wordpress.com",
215+
getCustomOauthAuthorizePath(serviceMap)
216+
?: "/oauth/authorize",
217+
clientId,
218+
serverUrl,
219+
SERVICE_NAME_WORDPRESS,
220+
state,
221+
getCustomOauthScope(serviceMap) ?: "openid"
184222
)
185223
}
186-
totalSocialAccountsEnabled++
187-
}
188-
}
224+
totalSocialAccountsEnabled++
189225
}
226+
}
227+
}
228+
}
190229

191-
if (settings.isWordpressAuthenticationEnabled()) {
192-
getServiceMap(services, SERVICE_NAME_WORDPRESS)?.let { serviceMap ->
193-
getOauthClientId(serviceMap)?.let { clientId ->
194-
wordpressOauthUrl =
195-
if (settings.wordpressUrl().isNullOrEmpty()) {
196-
OauthHelper.getWordpressComOauthUrl(
197-
clientId,
198-
serverUrl,
199-
state
200-
)
201-
} else {
202-
OauthHelper.getWordpressCustomOauthUrl(
203-
getCustomOauthHost(serviceMap)
204-
?: "https://public-api.wordpress.com",
205-
getCustomOauthAuthorizePath(serviceMap)
206-
?: "/oauth/authorize",
207-
clientId,
208-
serverUrl,
209-
SERVICE_NAME_WORDPRESS,
210-
state,
211-
getCustomOauthScope(serviceMap) ?: "openid"
212-
)
213-
}
214-
totalSocialAccountsEnabled++
215-
}
216-
}
217-
}
230+
private fun checkEnabledCasAccounts(serverUrl: String) {
231+
if (settings.isCasAuthenticationEnabled()) {
232+
casToken = generateRandomString(17)
233+
casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
234+
totalSocialAccountsEnabled++
235+
}
236+
}
218237

219-
// CAS account.
220-
if (settings.isCasAuthenticationEnabled()) {
221-
casToken = generateRandomString(17)
222-
casLoginUrl = settings.casLoginUrl().casUrl(serverUrl, casToken.toString())
238+
private fun checkEnabledCustomOauthAccounts(services: List<Map<String,Any>>, serverUrl: String) {
239+
getCustomOauthServices(services).let {
240+
for (serviceMap in it) {
241+
customOauthServiceName = getCustomOauthServiceName(serviceMap)
242+
val host = getCustomOauthHost(serviceMap)
243+
val authorizePath = getCustomOauthAuthorizePath(serviceMap)
244+
val clientId = getOauthClientId(serviceMap)
245+
val scope = getCustomOauthScope(serviceMap)
246+
val serviceNameTextColor =
247+
getServiceNameColorForCustomOauthOrSaml(serviceMap)
248+
val serviceButtonColor = getServiceButtonColor(serviceMap)
249+
if (customOauthServiceName != null &&
250+
host != null &&
251+
authorizePath != null &&
252+
clientId != null &&
253+
scope != null &&
254+
serviceNameTextColor != null &&
255+
serviceButtonColor != null
256+
) {
257+
customOauthUrl = OauthHelper.getCustomOauthUrl(
258+
host,
259+
authorizePath,
260+
clientId,
261+
serverUrl,
262+
customOauthServiceName.toString(),
263+
state,
264+
scope
265+
)
266+
customOauthServiceNameTextColor = serviceNameTextColor
267+
customOauthServiceButtonColor = serviceButtonColor
223268
totalSocialAccountsEnabled++
224269
}
270+
}
271+
}
272+
}
225273

226-
// Custom OAuth account.
227-
getCustomOauthServices(services).let {
228-
for (serviceMap in it) {
229-
customOauthServiceName = getCustomOauthServiceName(serviceMap)
230-
val host = getCustomOauthHost(serviceMap)
231-
val authorizePath = getCustomOauthAuthorizePath(serviceMap)
232-
val clientId = getOauthClientId(serviceMap)
233-
val scope = getCustomOauthScope(serviceMap)
234-
val serviceNameTextColor =
235-
getServiceNameColorForCustomOauthOrSaml(serviceMap)
236-
val serviceButtonColor = getServiceButtonColor(serviceMap)
237-
if (customOauthServiceName != null &&
238-
host != null &&
239-
authorizePath != null &&
240-
clientId != null &&
241-
scope != null &&
242-
serviceNameTextColor != null &&
243-
serviceButtonColor != null
244-
) {
245-
246-
customOauthUrl = OauthHelper.getCustomOauthUrl(
247-
host,
248-
authorizePath,
249-
clientId,
250-
serverUrl,
251-
customOauthServiceName.toString(),
252-
state,
253-
scope
254-
)
255-
customOauthServiceNameTextColor = serviceNameTextColor
256-
customOauthServiceButtonColor = serviceButtonColor
257-
totalSocialAccountsEnabled++
258-
}
259-
}
260-
}
261-
262-
// SAML account.
263-
getSamlServices(services).let {
264-
samlToken = generateRandomString(17)
265-
for (serviceMap in it) {
266-
val provider = getSamlProvider(serviceMap)
267-
samlServiceName = getSamlServiceName(serviceMap)
268-
val serviceNameTextColor =
269-
getServiceNameColorForCustomOauthOrSaml(serviceMap)
270-
val serviceButtonColor = getServiceButtonColor(serviceMap)
271-
272-
if (provider != null &&
273-
samlServiceName != null &&
274-
serviceNameTextColor != null &&
275-
serviceButtonColor != null
276-
) {
277-
samlUrl = serverUrl.samlUrl(provider, samlToken.toString())
278-
samlServiceNameTextColor = serviceNameTextColor
279-
samlServiceButtonColor = serviceButtonColor
280-
totalSocialAccountsEnabled++
281-
}
282-
}
274+
private fun checkEnabledSamlAccounts(services: List<Map<String,Any>>, serverUrl: String) {
275+
getSamlServices(services).let {
276+
samlToken = generateRandomString(17)
277+
for (serviceMap in it) {
278+
val provider = getSamlProvider(serviceMap)
279+
samlServiceName = getSamlServiceName(serviceMap)
280+
val serviceNameTextColor =
281+
getServiceNameColorForCustomOauthOrSaml(serviceMap)
282+
val serviceButtonColor = getServiceButtonColor(serviceMap)
283+
284+
if (provider != null &&
285+
samlServiceName != null &&
286+
serviceNameTextColor != null &&
287+
serviceButtonColor != null
288+
) {
289+
samlUrl = serverUrl.samlUrl(provider, samlToken.toString())
290+
samlServiceNameTextColor = serviceNameTextColor
291+
samlServiceButtonColor = serviceButtonColor
292+
totalSocialAccountsEnabled++
283293
}
284294
}
285-
} catch (exception: RocketChatException) {
286-
Timber.e(exception)
287295
}
288296
}
289297

0 commit comments

Comments
 (0)