Skip to content

Commit

Permalink
ADST-566 (#366)
Browse files Browse the repository at this point in the history
* ADST-422 OIDC. changes for Auth0 (#352)

* added auth0 authentication

* auth0 integrated

* code review correction

* ADST-528 (#353)

* fixed cache clear login crash

* save auth changes

* save aws changes

* saved changes for app auth

* added auth0 authentication

* linked latest app auth dependencies

* removed unused code

* code updated

* optimize code
  • Loading branch information
aman-alfresco authored Dec 12, 2024
1 parent 0948f42 commit 8d532ea
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 18 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ android {
versionName "1.10.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

}

signingConfigs {
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@
android:path="/auth"
android:scheme="androidacsapp" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="*.auth0.com"
android:scheme="demo"
android:path="/android/com.alfresco.content.app.debug/callback"/>
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="*.auth0.com"
android:scheme="demo"
android:path="/android/com.alfresco.content.app/callback"/>
</intent-filter>
</activity>
<activity
android:name="com.alfresco.content.browse.preview.LocalPreviewActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,9 @@ class MainActivity : AppCompatActivity(), MavericksView, ActionMode.Callback {
Handler(Looper.getMainLooper()).post {
viewModel.entriesMultiSelection = it.selectedEntries
if (it.isMultiSelectionEnabled) {
println("MainActivity.onCreate test 1")
viewModel.path = it.path
enableMultiSelection(it.selectedEntries)
} else {
println("MainActivity.onCreate test 2")
disableMultiSelection()
}
}
Expand Down
1 change: 1 addition & 0 deletions auth/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
implementation project(':theme')
implementation project(':data')
implementation project(':common')
implementation project(':component')

implementation libs.kotlin.stdlib

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ abstract class LoginActivity : AuthenticationActivity<LoginViewModel>() {
LoginViewModel.Step.InputIdentityServer -> InputIdentityFragment.with(this).display()
LoginViewModel.Step.InputAppServer -> InputServerFragment.with(this).display()
LoginViewModel.Step.EnterBasicCredentials -> BasicAuthFragment.with(this).display()
LoginViewModel.Step.EnterPkceCredentials -> viewModel.ssoLogin()
LoginViewModel.Step.EnterPkceCredentials -> {
viewModel.ssoLogin()
}

LoginViewModel.Step.Cancelled -> finish()
}
}
Expand Down
66 changes: 56 additions & 10 deletions auth/src/main/kotlin/com/alfresco/auth/activity/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import androidx.lifecycle.viewModelScope
import com.alfresco.android.aims.R
import com.alfresco.auth.AuthConfig
import com.alfresco.auth.AuthType
import com.alfresco.auth.AuthTypeProvider
import com.alfresco.auth.IdentityProvider
import com.alfresco.auth.config.defaultConfig
import com.alfresco.auth.data.LiveEvent
import com.alfresco.auth.data.MutableLiveEvent
import com.alfresco.auth.data.OAuth2Data
import com.alfresco.auth.ui.AuthenticationViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -57,7 +60,7 @@ class LoginViewModel(
val canonicalApplicationUrl: String
get() {
return previousAppEndpoint
?: discoveryService.contentServiceUrl(applicationUrl.value!!).toString()
?: discoveryService.contentServiceUrl(applicationUrl.value!!, authConfig.authType).toString()
}

// Used for display purposes
Expand Down Expand Up @@ -100,6 +103,7 @@ class LoginViewModel(

fun connect() {
isLoading.value = true
loadSavedConfig()

try {
checkAuthType(identityUrl.value!!, authConfig, ::onAuthType)
Expand All @@ -108,20 +112,58 @@ class LoginViewModel(
}
}

private fun onAuthType(authType: AuthType) {
private fun onAuthType(
authType: AuthType,
oAuth2Data: OAuth2Data?,
) {
when {
oAuth2Data != null && oAuth2Data.authType?.lowercase() == IdentityProvider.AUTH0.value() -> {
val host = Uri.parse(oAuth2Data.host).host ?: ""
var additionalParams = mutableMapOf<String, String>()
if (oAuth2Data.audience.isNotEmpty()) {
val key = OAuth2Data::audience.name
val value = oAuth2Data.audience

additionalParams[key] = value
}
authConfig =
AuthConfig(
https = authConfig.https,
port = "",
contentServicePath = "",
realm = "",
clientId = oAuth2Data.clientId,
redirectUrl = "demo://$host/android/${context.packageName}/callback",
host = host,
secret = oAuth2Data.secret,
scope = oAuth2Data.scope,
authType = AuthTypeProvider.NEW_IDP,
additionalParams = additionalParams,
)
}
}

when (authType) {
AuthType.PKCE -> {
viewModelScope.launch {
val isContentServicesInstalled =
withContext(Dispatchers.IO) {
discoveryService.isContentServiceInstalled(identityUrl.value ?: "")
when (authConfig.authType) {
AuthTypeProvider.NEW_IDP -> {
applicationUrl.value = identityUrl.value
moveToStep(Step.EnterPkceCredentials)
}

if (isContentServicesInstalled) {
applicationUrl.value = identityUrl.value
moveToStep(Step.EnterPkceCredentials)
} else {
moveToStep(Step.InputAppServer)
else -> {
val isContentServicesInstalled =
withContext(Dispatchers.IO) {
discoveryService.isContentServiceInstalled(identityUrl.value ?: "")
}
if (isContentServicesInstalled) {
applicationUrl.value = identityUrl.value
moveToStep(Step.EnterPkceCredentials)
} else {
moveToStep(Step.InputAppServer)
}
}
}
}
}
Expand Down Expand Up @@ -199,15 +241,19 @@ class LoginViewModel(
when (step) {
Step.InputIdentityServer -> {
}

Step.InputAppServer -> {
applicationUrl.value = ""
}

Step.EnterBasicCredentials -> {
// Assume application url is the same as identity for basic auth
applicationUrl.value = identityUrl.value
}

Step.EnterPkceCredentials -> {
}

Step.Cancelled -> {
}
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

buildscript {
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ data class ComponentData(
outcomes: List<OptionsModel>,
name: String,
query: String,
title: String = "",
selector: String = ComponentType.PROCESS_ACTION.value,
): ComponentData {
return ComponentData(
selector = ComponentType.PROCESS_ACTION.value,
name = title,
selector = selector,
options = outcomes.map { ComponentOptions.withProcess(it) },
selectedName = name,
selectedQuery = query,
Expand Down
6 changes: 2 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ activity-compose = "1.9.2"
compose-bom = "2024.09.03"
ui-tooling = "1.7.3"
constraintlayout = "2.1.4"
moshi = "1.15.1"
retrofit = "2.11.0"

[libraries]
alfresco-auth = "com.alfresco.android:auth:0.8.3-SNAPSHOT"
alfresco-auth = "com.alfresco.android:auth:0.8.4-SNAPSHOT"
alfresco-content = "com.alfresco.android:content:0.3.6-SNAPSHOT"
alfresco-contentKtx = "com.alfresco.android:content-ktx:0.3.3-SNAPSHOT"
alfresco-process = "com.alfresco.android:process:0.1.4-SNAPSHOT"
Expand Down Expand Up @@ -131,4 +129,4 @@ ui-compose-viewbinding = "androidx.compose.ui:ui-viewbinding:1.7.3"
navigation-compose = "androidx.navigation:navigation-compose:2.8.2"
compose-runtime = "androidx.compose.runtime:runtime:1.7.3"
androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling", version.ref = "ui-tooling" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
4 changes: 4 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ include ':move'
include ':component'
include ':app'
include ':process-app'
//include ':alfresco-auth'
//include ':content'
//include ':content-ktx'

// Enable Gradle's version catalog support
// Ref: https://docs.gradle.org/current/userguide/platforms.html
//enableFeaturePreview("VERSION_CATALOGS")

0 comments on commit 8d532ea

Please sign in to comment.