Skip to content

Commit f63af4c

Browse files
Merge pull request #10
feat: Add flow type option for Supabase authentication and refactor related configurations
2 parents 205fe84 + 8b5fb05 commit f63af4c

File tree

7 files changed

+41
-12
lines changed

7 files changed

+41
-12
lines changed

convention-plugins/src/main/kotlin/root.publication.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ plugins {
55
// these will be used for all projects ie. kmauth-core, kmauth-google etc.
66
allprojects {
77
group = "io.github.sunildhiman90"
8-
version = "0.3.0"
8+
version = "0.3.1"
99
}

kmauth-core/src/commonMain/kotlin/com/sunildhiman90/kmauth/core/KMAuthConfig.kt

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ data class KMAuthConfig(
1414
* A unique identifier for the provider (e.g., "google", "supabase").
1515
* This is used to store and retrieve the configuration for different providers.
1616
*/
17-
val providerId: String,
17+
val providerId: String = "default",
1818

1919
val kmAuthPlatformContext: KMAuthPlatformContext? = null,
2020
val webClientId: String? = null,
@@ -26,7 +26,8 @@ data class KMAuthConfig(
2626
val autoLoadFromStorage: Boolean = true,
2727
val autoRefreshToken: Boolean = true,
2828
val deepLinkHost: String? = null,
29-
val deepLinkScheme: String? = null
29+
val deepLinkScheme: String? = null,
30+
val flowType: KMAuthSupabaseFlowType? = null
3031
) {
3132
init {
3233
// Validate Supabase configuration if URL or key is provided
@@ -40,51 +41,48 @@ data class KMAuthConfig(
4041
/**
4142
* Creates a [KMAuthConfig] for Supabase authentication.
4243
*
43-
* @param providerId A unique identifier for this provider
4444
* @param kmAuthPlatformContext The platform-specific context (e.g., Android Context).
4545
* @param supabaseUrl The Supabase project URL.
4646
* @param supabaseKey The Supabase anon/public key.
4747
* @param autoLoadFromStorage Whether to automatically load authentication data from storage.
4848
* @param autoRefreshToken Whether to automatically refresh access tokens.
4949
* @param deepLinkHost The host for Android/ios deep links for oauth.
5050
* @param deepLinkScheme The scheme for Android/ios deep links for oauth.
51+
* @param kmAuthSupabaseFlowType The flow type for Supabase authentication.
5152
*/
5253
fun forSupabase(
53-
providerId: String = "supabase",
5454
supabaseUrl: String,
5555
supabaseKey: String,
5656
kmAuthPlatformContext: KMAuthPlatformContext? = null,
5757
autoLoadFromStorage: Boolean = true,
5858
autoRefreshToken: Boolean = true,
5959
deepLinkHost: String? = null,
60-
deepLinkScheme: String? = null
60+
deepLinkScheme: String? = null,
61+
kmAuthSupabaseFlowType: KMAuthSupabaseFlowType? = null
6162
): KMAuthConfig = KMAuthConfig(
62-
providerId = providerId,
6363
kmAuthPlatformContext = kmAuthPlatformContext,
6464
supabaseUrl = supabaseUrl,
6565
supabaseKey = supabaseKey,
6666
autoLoadFromStorage = autoLoadFromStorage,
6767
autoRefreshToken = autoRefreshToken,
6868
deepLinkHost = deepLinkHost,
69-
deepLinkScheme = deepLinkScheme
69+
deepLinkScheme = deepLinkScheme,
70+
flowType = kmAuthSupabaseFlowType
7071
)
7172

7273
/**
7374
* Creates a [KMAuthConfig] for Google authentication.
7475
*
75-
* @param providerId A unique identifier for this provider (e.g., "google-main", "google-backup").
7676
* @param kmAuthPlatformContext The platform-specific context (e.g., Android Context).
7777
* @param webClientId The OAuth web client ID.
7878
* @param clientSecret The OAuth client secret.
7979
*/
8080
fun forGoogle(
8181
webClientId: String,
82-
providerId: String = "google",
8382
kmAuthPlatformContext: KMAuthPlatformContext? = null,
8483
clientSecret: String? = null
8584
): KMAuthConfig {
8685
val kmAuthConfig = KMAuthConfig(
87-
providerId = providerId,
8886
webClientId = webClientId,
8987
clientSecret = clientSecret
9088
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.sunildhiman90.kmauth.core
2+
3+
4+
/**
5+
* Enum class for Supabase authentication flow types.
6+
*/
7+
enum class KMAuthSupabaseFlowType {
8+
IMPLICIT,
9+
PKCE;
10+
11+
companion object {
12+
fun fromValue(value: String): KMAuthSupabaseFlowType {
13+
return entries.firstOrNull { it.name == value } ?: throw IllegalArgumentException("Invalid KMAuthSupabaseFlowType: $value")
14+
}
15+
}
16+
}

kmauth-google/kmauth_google.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'kmauth_google'
3-
spec.version = '0.3.0'
3+
spec.version = '0.3.1'
44
spec.homepage = ''
55
spec.source = { :http=> ''}
66
spec.authors = ''

kmauth-supabase/src/commonMain/kotlin/com/sunildhiman90/kmauth/supabase/KMAuthSupabase.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ import com.sunildhiman90.kmauth.supabase.model.SupabaseDefaultAuthProvider
1010
import com.sunildhiman90.kmauth.supabase.model.SupabaseOAuthProvider
1111
import com.sunildhiman90.kmauth.supabase.model.SupabaseUser
1212
import com.sunildhiman90.kmauth.supabase.model.toSupabaseUser
13+
import com.sunildhiman90.kmauth.supabase.utils.toFlowType
1314
import io.github.jan.supabase.SupabaseClient
1415
import io.github.jan.supabase.auth.Auth
16+
import io.github.jan.supabase.auth.FlowType
1517
import io.github.jan.supabase.auth.auth
1618
import io.github.jan.supabase.auth.status.SessionStatus
1719
import io.github.jan.supabase.createSupabaseClient
@@ -67,6 +69,7 @@ object KMAuthSupabase : CoroutineScope {
6769
this.autoLoadFromStorage = config.autoLoadFromStorage
6870
this.alwaysAutoRefresh = config.autoRefreshToken
6971
redirectUrl?.let { this.defaultRedirectUrl = it }
72+
flowType = config.flowType?.toFlowType() ?: FlowType.IMPLICIT
7073

7174
//Android and ios deep links
7275
config.deepLinkHost?.let { this.host = it }

kmauth-supabase/src/commonMain/kotlin/com/sunildhiman90/kmauth/supabase/model/SupabaseOAuthProvider.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import io.github.jan.supabase.auth.providers.Github
99
import io.github.jan.supabase.auth.providers.Gitlab
1010
import io.github.jan.supabase.auth.providers.Google
1111
import io.github.jan.supabase.auth.providers.IDTokenProvider
12+
import io.github.jan.supabase.auth.providers.Keycloak
1213
import io.github.jan.supabase.auth.providers.LinkedIn
1314
import io.github.jan.supabase.auth.providers.OAuthProvider
1415
import io.github.jan.supabase.auth.providers.Slack
@@ -29,6 +30,7 @@ enum class SupabaseOAuthProvider {
2930
SPOTIFY,
3031
TWITCH,
3132
LINKEDIN,
33+
KEYCLOAK,
3234

3335
// IDTokenProviders
3436
GOOGLE,
@@ -51,6 +53,7 @@ enum class SupabaseOAuthProvider {
5153
LINKEDIN -> LinkedIn
5254
APPLE -> Apple
5355
AZURE -> Azure
56+
KEYCLOAK -> Keycloak
5457
}
5558
}
5659

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.sunildhiman90.kmauth.supabase.utils
2+
3+
import com.sunildhiman90.kmauth.core.KMAuthSupabaseFlowType
4+
import io.github.jan.supabase.auth.FlowType
5+
6+
fun KMAuthSupabaseFlowType.toFlowType(): FlowType = when (this) {
7+
KMAuthSupabaseFlowType.IMPLICIT -> FlowType.IMPLICIT
8+
KMAuthSupabaseFlowType.PKCE -> FlowType.PKCE
9+
}

0 commit comments

Comments
 (0)