Skip to content

Commit

Permalink
Merge pull request #57 from Achintha444/main
Browse files Browse the repository at this point in the history
[asgardeo-android] changed `SharedFlow` to `StateFlow`.
  • Loading branch information
Achintha444 authored Sep 2, 2024
2 parents bcd0152 + b9feda5 commit 7565a41
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.activity.result.ActivityResultLauncher
import androidx.annotation.RequiresApi
import io.asgardeo.android.core_auth_direct.models.autheniticator.Authenticator
import io.asgardeo.android.core_auth_direct.models.state.AuthenticationState
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow

/**
* Authentication provider manager that is used to manage the authentication process.
Expand All @@ -42,9 +42,9 @@ internal interface AuthenticationProviderManager {
/**
* Get authentication state flow of the authentication state which is exposed to the outside.
*
* @return authentication state flow [SharedFlow<AuthenticationState>]
* @return authentication state flow [StateFlow<AuthenticationState>]
*/
fun getAuthenticationStateFlow(): SharedFlow<AuthenticationState>
fun getAuthenticationStateFlow(): StateFlow<AuthenticationState>

/**
* Check whether the user is logged in or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import io.asgardeo.android.core_auth_direct.models.state.AuthenticationState
import io.asgardeo.android.core_auth_direct.provider.provider_managers.authenticate_handler.AuthenticateHandlerProviderManager
import io.asgardeo.android.core_auth_direct.provider.provider_managers.authentication.AuthenticationProviderManager
import io.asgardeo.android.core_auth_direct.provider.provider_managers.authentication_state.AuthenticationStateProviderManager
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import java.lang.ref.WeakReference

/**
Expand Down Expand Up @@ -110,9 +110,9 @@ internal class AuthenticationProviderManagerImpl private constructor(
/**
* Get authentication state flow of the authentication state which is exposed to the outside.
*
* @return authentication state flow [SharedFlow<AuthenticationState>]
* @return authentication state flow [StateFlow<AuthenticationState>]
*/
override fun getAuthenticationStateFlow(): SharedFlow<AuthenticationState> =
override fun getAuthenticationStateFlow(): StateFlow<AuthenticationState> =
authenticationStateProviderManager.getAuthenticationStateFlow()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import android.content.Context
import io.asgardeo.android.core_auth_direct.models.autheniticator.Authenticator
import io.asgardeo.android.core_auth_direct.models.authentication_flow.AuthenticationFlow
import io.asgardeo.android.core_auth_direct.models.state.AuthenticationState
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow

/**
* Authentication state provider manager that is used to manage the authentication state.
Expand All @@ -37,9 +37,9 @@ interface AuthenticationStateProviderManager {
/**
* Get authentication state flow
*
* @return authentication state flow [SharedFlow<AuthenticationState>]
* @return authentication state flow [StateFlow<AuthenticationState>]
*/
fun getAuthenticationStateFlow(): SharedFlow<AuthenticationState>
fun getAuthenticationStateFlow(): StateFlow<AuthenticationState>

/**
* Emit the authentication state.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.asgardeo.android.core_auth_direct.models.state.AuthenticationState
import io.asgardeo.android.core_auth_direct.models.state.TokenState
import io.asgardeo.android.core_auth_direct.provider.provider_managers.authentication_state.AuthenticationStateProviderManager
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import java.lang.ref.WeakReference

Expand Down Expand Up @@ -92,9 +91,9 @@ internal class AuthenticationStateProviderManagerImpl private constructor(
/**
* Get authentication state flow
*
* @return authentication state flow [SharedFlow<AuthenticationState>]
* @return authentication state flow [StateFlow<AuthenticationState>]
*/
override fun getAuthenticationStateFlow(): SharedFlow<AuthenticationState> =
override fun getAuthenticationStateFlow(): StateFlow<AuthenticationState> =
authenticationStateFlow

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.annotation.RequiresApi
import io.asgardeo.android.core_auth_direct.models.autheniticator.Authenticator
import io.asgardeo.android.core_auth_direct.models.state.AuthenticationState
import io.asgardeo.android.core_auth_direct.provider.providers.authentication.impl.AuthenticationProviderImpl
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow

/**
* Interface for the authentication provider to be implemented by the application.
Expand All @@ -37,9 +37,9 @@ interface AuthenticationProvider {
/**
* Get authentication state flow
*
* @return authentication state flow [SharedFlow<AuthenticationState>]
* @return authentication state flow [StateFlow<AuthenticationState>]
*/
fun getAuthenticationStateFlow(): SharedFlow<AuthenticationState>
fun getAuthenticationStateFlow(): StateFlow<AuthenticationState>

/**
* Check whether the user is logged in or not.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import io.asgardeo.android.core_auth_direct.models.state.AuthenticationState
import io.asgardeo.android.core_auth_direct.provider.provider_managers.authentication.AuthenticationProviderManager
import io.asgardeo.android.core_auth_direct.provider.provider_managers.user.UserProviderManager
import io.asgardeo.android.core_auth_direct.provider.providers.authentication.AuthenticationProvider
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import java.lang.ref.WeakReference

/**
Expand Down Expand Up @@ -89,9 +89,9 @@ internal class AuthenticationProviderImpl private constructor(
/**
* Get authentication state flow
*
* @return authentication state flow [SharedFlow<AuthenticationState>]
* @return authentication state flow [StateFlow<AuthenticationState>]
*/
override fun getAuthenticationStateFlow(): SharedFlow<AuthenticationState> =
override fun getAuthenticationStateFlow(): StateFlow<AuthenticationState> =
authenticationProviderManager.getAuthenticationStateFlow()

/**
Expand Down
11 changes: 6 additions & 5 deletions docs/website/android/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
AuthenticationCoreConfig(
discoveryEndpoint = "https://api.asgardeo.io/t/<org_name>/oauth2/token/.well-known/openid-configuration",
authnEndpoint = "https://api.asgardeo.io/t/<org_name>/oauth2/authn",
redirectUri = "wso2sample://oauth2",
redirectUri = "wso2.apiauth.sample.android://oauth2",
clientId = "<client_id>",
scope = "openid profile email"
)
Expand All @@ -39,7 +39,7 @@
val authenticationProvider: AuthenticationProvider = asgardeoAuth.getAuthenticationProvider()
```

<a href="/mobile-ui-sdks/android/api/core-auth-direct/io.asgardeo.android.core_auth_direct.provider.providers.authentication/-authentication-provider/index.html" target="_blank">AuthenticationProvider</a> handles the authentication process using [SharedFlow](https://developer.android.com/kotlin/flow/stateflow-and-sharedflow#sharedflow). This will help you to handle each state of the authentication process easily. There are four states in the authentication process (<a href="/mobile-ui-sdks/android/api/core-auth-direct/io.asgardeo.android.core_auth_direct.models.state/-authentication-state/index.html" target="_blank">AuthenticationState</a>):
<a href="/mobile-ui-sdks/android/api/core-auth-direct/io.asgardeo.android.core_auth_direct.provider.providers.authentication/-authentication-provider/index.html" target="_blank">AuthenticationProvider</a> handles the authentication process using [StateFlow](https://developer.android.com/kotlin/flow/stateflow-and-sharedflow#stateflow). This will help you to handle each state of the authentication process easily. There are four states in the authentication process (<a href="/mobile-ui-sdks/android/api/core-auth-direct/io.asgardeo.android.core_auth_direct.models.state/-authentication-state/index.html" target="_blank">AuthenticationState</a>):

- **AuthenticationState.Initial**: Initial state of the authentication process.
- **AuthenticationState.Loading**: SDK is calling an API to handle the authentication and waiting for the result.
Expand All @@ -64,10 +64,11 @@ Then call the `authenticationProvider.initializeAuthentication` to initialize th
```kotlin
@Composable
internal fun LandingScreen() {
val context: Context = LocalContext.current
val authenticationStateFlow = authenticationProvider.getAuthenticationStateFlow()

IsLoggedInStateFlow()
HandleAuthenticationState(authenticationStateFlow)
IsLoggedInStateFlow(context)
HandleAuthenticationState(authenticationStateFlow, context)
}

@Composable
Expand All @@ -80,7 +81,7 @@ private fun IsLoggedInStateFlow(context: Context) {
}

@Composable
private fun HandleAuthenticationState(authenticationStateFlow: SharedFlow<AuthenticationState>) {
private fun HandleAuthenticationState(authenticationStateFlow: StateFlow<AuthenticationState>) {
LaunchedEffect(key1 = Unit) {
GlobalScope.launch {
authenticationStateFlow.collect {
Expand Down

0 comments on commit 7565a41

Please sign in to comment.