Skip to content

Commit

Permalink
code correction
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Jul 5, 2024
1 parent e3845c1 commit 228e1bc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
10 changes: 0 additions & 10 deletions auth/src/main/java/com/alfresco/auth/AuthInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,16 +229,6 @@ class AuthInterceptor(
override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(AuthType.OIDC, accessToken)

// When unauthorized try to refresh
// if (response.code == HTTP_RESPONSE_401_UNAUTHORIZED) {
// val newState = refreshTokenNow()
//
// if (newState != null) {
// response.close()
// response = chain.proceed(AuthType.PKCE, newState.accessToken)
// }
// }

// If still error notify listener of failure
if (response.code == HTTP_RESPONSE_401_UNAUTHORIZED) {
listener?.onAuthFailure(accountId, response.request.url.toString())
Expand Down
8 changes: 5 additions & 3 deletions auth/src/main/java/com/alfresco/auth/DiscoveryService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ class DiscoveryService(

when (authConfig.authType.lowercase()) {
AuthType.OIDC.value -> {
if (isOIDC(endpoint)){
if (isOIDC(endpoint)) {
return AuthType.OIDC
}
}

AuthType.PKCE.value -> {
if (isPkceType(endpoint)){
if (isPkceType(endpoint)) {
return AuthType.PKCE
}
}
Expand Down Expand Up @@ -145,7 +146,8 @@ class DiscoveryService(
return result != null
}

private suspend fun isOIDC(endpoint: String): Boolean = isOIDCInstalled(endpoint) && authConfig.realm.isBlank()
private suspend fun isOIDC(endpoint: String): Boolean =
isOIDCInstalled(endpoint) && authConfig.realm.isBlank()

/**
* Return content service url based on [endpoint].
Expand Down
11 changes: 2 additions & 9 deletions auth/src/main/java/com/alfresco/auth/pkce/PkceAuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ internal class PkceAuthService(context: Context, authState: AuthState?, authConf
val authDetails = getAppConfigOAuth2Details(uri)

authDetails?.let { oauth2 ->
println("PkceAuthService.initiateLogin $authDetails")

val credentials = webAuthAsync(
oauth2,
Expand Down Expand Up @@ -172,11 +171,7 @@ internal class PkceAuthService(context: Context, authState: AuthState?, authConf
): Credentials? {
return try {
val host = URL(oauth2.host).host
Log.d("Test OIDC -1 :: ", oauth2.clientId)
Log.d("Test OIDC 0 :: ", host)
Log.d("Test OIDC 1 :: ", activity.getString(R.string.com_auth0_scheme))
Log.d("Test OIDC 2 :: ", oauth2.audience)
Log.d("Test OIDC 3 :: ", oauth2.scope)


val account = Auth0(oauth2.clientId, host)
val credentials = WebAuthProvider.login(account)
Expand All @@ -185,12 +180,10 @@ internal class PkceAuthService(context: Context, authState: AuthState?, authConf
.withScope(oauth2.scope)
.withAudience(oauth2.audience)
.await(activity)
Log.d("Test OIDC 4 :: ", "Success: ${credentials.accessToken}")
credentials
credentials
} catch (error: AuthenticationException) {
val message =
if (error.isCanceled) "Browser was closed" else error.getDescription()
Log.d("Test OIDC 5 :: ", "Failure: $message")
null
}
}
Expand Down

0 comments on commit 228e1bc

Please sign in to comment.