{"id":13659629,"url":"https://github.com/mirzemehdi/KMPAuth","last_synced_at":"2025-04-24T15:30:31.172Z","repository":{"id":214427519,"uuid":"736339532","full_name":"mirzemehdi/KMPAuth","owner":"mirzemehdi","description":"Kotlin Multiplatform Authentication Library targetting android and iOS ","archived":false,"fork":false,"pushed_at":"2025-01-15T12:36:09.000Z","size":529,"stargazers_count":268,"open_issues_count":13,"forks_count":27,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-15T13:25:24.709Z","etag":null,"topics":["android","authentication","google-auth-library","google-authentication","ios","kotlin-multiplatform","kotlin-multiplatform-library","kotlin-multiplatform-mobile"],"latest_commit_sha":null,"homepage":"https://mirzemehdi.com/KMPAuth/","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mirzemehdi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-12-27T16:30:11.000Z","updated_at":"2025-01-15T02:36:36.000Z","dependencies_parsed_at":"2024-01-25T07:24:49.792Z","dependency_job_id":"7deb0c51-426b-4bcb-8f31-b225f0f04db4","html_url":"https://github.com/mirzemehdi/KMPAuth","commit_stats":null,"previous_names":["mirzemehdi/kmpauth"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirzemehdi%2FKMPAuth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirzemehdi%2FKMPAuth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirzemehdi%2FKMPAuth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mirzemehdi%2FKMPAuth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mirzemehdi","download_url":"https://codeload.github.com/mirzemehdi/KMPAuth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250654071,"owners_count":21465806,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","authentication","google-auth-library","google-authentication","ios","kotlin-multiplatform","kotlin-multiplatform-library","kotlin-multiplatform-mobile"],"created_at":"2024-08-02T05:01:10.714Z","updated_at":"2025-04-24T15:30:30.722Z","avatar_url":"https://github.com/mirzemehdi.png","language":"Kotlin","funding_links":[],"categories":["Libraries"],"sub_categories":["🍎 Compose UI"],"readme":"# KMPAuth - Kotlin Multiplatform Authentication Library\n[![Build](https://github.com/mirzemehdi/KMPAuth/actions/workflows/build_and_publish.yml/badge.svg)](https://github.com/mirzemehdi/KMPAuth/actions/workflows/build_and_publish.yml)\n[![Kotlin](https://img.shields.io/badge/Kotlin-2.0.20-blue.svg?style=flat\u0026logo=kotlin)](https://kotlinlang.org)\n[![Maven Central](https://img.shields.io/maven-central/v/io.github.mirzemehdi/kmpauth-google?color=blue)](https://search.maven.org/search?q=g:io.github.mirzemehdi+kmpauth)\n\n![badge-android](http://img.shields.io/badge/platform-android-6EDB8D.svg?style=flat)\n![badge-ios](http://img.shields.io/badge/platform-ios-CDCDCD.svg?style=flat)\n\nSimple and easy to use Kotlin Multiplatform Authentication library targeting iOS and Android. Supporting **Google**, **Apple**, **Github** authentication integrations using Firebase.   \nBecause I am using KMPAuth in [FindTravelNow](https://github.com/mirzemehdi/FindTravelNow-KMM/) production KMP project, I'll support development of this library :).   \nRelated blog post: [Integrating Google Sign-In into Kotlin Multiplatform](https://proandroiddev.com/integrating-google-sign-in-into-kotlin-multiplatform-8381c189a891)  \nYou can check out [Documentation](https://mirzemehdi.github.io/KMPAuth) for full library api information.\n\n## Sample App and Code\n\u003cp style=\"text-align: center;\"\u003e\n  \u003cimg src=\"https://github.com/mirzemehdi/KMPAuth/assets/32781662/f5a3cd28-6ef2-46bf-9b07-a045ce217b34)\" width=\"200\" alt=\"SampleApp\"/\u003e  \n\u003c/p\u003e\n\n```kotlin\n@Composable\nfun AuthUiHelperButtonsAndFirebaseAuth(\n    modifier: Modifier = Modifier,\n    onFirebaseResult: (Result\u003cFirebaseUser?\u003e) -\u003e Unit,\n) {\n    Column(modifier = modifier,verticalArrangement = Arrangement.spacedBy(10.dp)) {\n\n        //Google Sign-In Button and authentication with Firebase\n        GoogleButtonUiContainerFirebase(onResult = onFirebaseResult) {\n            GoogleSignInButton(modifier = Modifier.fillMaxWidth()) { this.onClick() }\n        }\n\n        //Apple Sign-In Button and authentication with Firebase\n        AppleButtonUiContainer(onResult = onFirebaseResult) {\n            AppleSignInButton(modifier = Modifier.fillMaxWidth()) { this.onClick() }\n        }\n\n        //Github Sign-In with Custom Button and authentication with Firebase\n        GithubButtonUiContainer(onResult = onFirebaseResult) {\n            Button(onClick = { this.onClick() }) { Text(\"Github Sign-In (Custom Design)\") }\n        }\n\n    }\n}\n\n```\n\n  \n\n\nYou can check out more [sample codes](https://github.com/mirzemehdi/KMPAuth/blob/main/sampleApp/composeApp/src/commonMain/kotlin/com/mmk/kmpauth/sample/App.kt) here.\n\n## Features\n- ✅ Google One Tap Sign-In (without Firebase)\n- ✅ [Google Sign-In with Firebase](#google-sign-in)\n- ✅ [Apple Sign-In with Firebase](#apple-sign-in)\n- ✅ [Github Sign-In with Firebase](#github-sign-in)\n- ✅ Apple and Google \"Sign in with \" UiHelper buttons (according to each brand's guideline)\n- 🚧 Facebook Sign-In (can be implemented in future)\n- 📱 Multiplatform (android and iOS)\n\n## Installation\nKMPAuth is available on Maven Central. In your root project `build.gradle.kts` file (or `settings.gradle` file) add `mavenCentral()` to repositories.\n\n```kotlin\nrepositories { \n  mavenCentral()\n}\n```\n\nThen in your shared module add desired dependencies in `commonMain`. Latest version: [![Maven Central](https://img.shields.io/maven-central/v/io.github.mirzemehdi/kmpauth-google?color=blue)](https://search.maven.org/search?q=g:io.github.mirzemehdi+kmpauth).\n```kotlin\nsourceSets {\n  commonMain.dependencies {\n    implementation(\"io.github.mirzemehdi:kmpauth-google:\u003cversion\u003e\") //Google One Tap Sign-In \n    implementation(\"io.github.mirzemehdi:kmpauth-firebase:\u003cversion\u003e\") //Integrated Authentications with Firebase\n    implementation(\"io.github.mirzemehdi:kmpauth-uihelper:\u003cversion\u003e\") //UiHelper SignIn buttons (AppleSignIn, GoogleSignInButton)\n\n  }\n}\n```\n**_You will also need to include Google Sign-In and/or FirebaseAuth library to your ios app using Swift Package Manager or Cocoapods._**   \n\n**Note**: If in iOS you get `MissingResourceException`, I wrote solution in this [issue's comment section](https://github.com/mirzemehdi/KMPAuth/issues/2).\n\n-----\n\n### Google Sign-In\nFor Google Sign-In you can either use only one-tap sign in functionality, or also implementing firebase google authentication integration to that.\nYou need to set up OAuth 2.0 in Google Cloud Platform Console. \nFor steps you can follow this [link](https://support.google.com/cloud/answer/6158849). **_Pro Easy Tip:_** If you use Firebase and enable Google Sign-In authentication in Firebase \nit will automatically generate OAuth client IDs for each platform, \nand one will be **_Web Client ID_** which will be needed for identifying signed-in users in backend server.\n\n#### Platform Setup\nCreate GoogleAuthProvider instance by providing _**Web Client Id**_ as a serverID on Application start.\n```kotlin\nGoogleAuthProvider.create(credentials = GoogleAuthCredentials(serverId = WebClientId))\n\n```\n\u003cdetails\u003e\n  \u003csummary\u003eAndroid\u003c/summary\u003e\n\n##### Android Setup\nThere is not any platform specific setup in Android side.\n\n\u003c/details\u003e\n\n\u003cdetails\u003e\n  \u003csummary\u003eiOS\u003c/summary\u003e\n\n##### iOS Setup\nAdd clientID, and serverId to your `Info.plist` file as below:\n\n```\n\u003ckey\u003eGIDServerClientID\u003c/key\u003e\n\u003cstring\u003eYOUR_SERVER_CLIENT_ID\u003c/string\u003e\n\n\u003ckey\u003eGIDClientID\u003c/key\u003e\n\u003cstring\u003eYOUR_IOS_CLIENT_ID\u003c/string\u003e\n\u003ckey\u003eCFBundleURLTypes\u003c/key\u003e\n\u003carray\u003e\n  \u003cdict\u003e\n    \u003ckey\u003eCFBundleURLSchemes\u003c/key\u003e\n    \u003carray\u003e\n      \u003cstring\u003eYOUR_DOT_REVERSED_IOS_CLIENT_ID\u003c/string\u003e\n    \u003c/array\u003e\n  \u003c/dict\u003e\n\u003c/array\u003e\n\n```\n\nAnd finally, you need the code below to implement application delegate function calls on the Swift side.\n\n```swift\nimport SwiftUI\nimport shared\nimport GoogleSignIn\n\nclass AppDelegate: NSObject, UIApplicationDelegate {\n\n    func application(\n      _ app: UIApplication,\n      open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]\n    ) -\u003e Bool {\n      var handled: Bool\n\n      handled = GIDSignIn.sharedInstance.handle(url)\n      if handled {\n        return true\n      }\n\n      // Handle other custom URL types.\n\n      // If not handled by this app, return false.\n      return false\n    }\n\n\n}\n\n@main\nstruct iOSApp: App {\n    @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate\n    \n   var body: some Scene {\n      WindowGroup {\n            ContentView().onOpenURL(perform: { url in\n                GIDSignIn.sharedInstance.handle(url)\n            })\n      }\n   }\n}\n\n\n```\n\n\u003c/details\u003e\n\n#### Usage\nAfter configuring above steps this is how you can use:\n\n```kotlin\n//Google Sign-In with Custom Button (only one tap sign-in functionality)\nGoogleButtonUiContainer(onGoogleSignInResult = { googleUser -\u003e\n  val idToken = googleUser?.idToken // Send this idToken to your backend to verify\n}) {\n  Button(onClick = { this.onClick() }) { Text(\"Google Sign-In(Custom Design)\") }\n}\n\n```\n\nGoogle Sign-In Button and authentication with Firebase. You need to implement `kmpauth-uihelper` dependency\n```kotlin\nGoogleButtonUiContainerFirebase(onResult = onFirebaseResult) {\n  GoogleSignInButton(modifier = Modifier.fillMaxWidth()) { this.onClick() }\n}\n```\n\nGoogle Sign-In IconOnly Button and authentication with Firebase. You need to implement `kmpauth-uihelper` dependency\n```kotlin\nGoogleButtonUiContainerFirebase(onResult = onFirebaseResult) {\n  GoogleSignInButtonIconOnly(onClick = { this.onClick() })\n}\n\n```\n\n### Apple Sign-In\nAfter enabling and configuring Apple Sign-In in Firebase, make sure you added \"Sign In with Apple\" capability in XCode. Then, you can use it as below in your @Composable function:\n```kotlin\n//Apple Sign-In with Custom Button and authentication with Firebase\nAppleButtonUiContainer(onResult = onFirebaseResult) {\n  //Any View, you just need to delegate child view's click to this UI Container's click method\n  Button(onClick = { this.onClick() }) { Text(\"Apple Sign-In (Custom Design)\") }\n}\n\n```\n\nApple Sign-In with AppleSignInButton. You need to implement `kmpauth-uihelper` dependency\n```kotlin\nAppleButtonUiContainer(onResult = onFirebaseResult) {\n  AppleSignInButton(modifier = Modifier.fillMaxWidth()) { this.onClick() }\n}\n```\n\nApple Sign-In IconOnly Button. You need to implement `kmpauth-uihelper` dependency\n```kotlin\nAppleButtonUiContainer(onResult = onFirebaseResult) {\n  AppleSignInButtonIconOnly(onClick = { this.onClick() })\n}\n\n```\n\n### Github Sign-In\nAfter enabling and configuring Github Sign-In in Firebase, you can use it as below in your @Composable function:\n```kotlin\n//Github Sign-In with Custom Button and authentication with Firebase\nGithubButtonUiContainer(onResult = onFirebaseResult) {\n  //Any View, you just need to delegate child view's click to this UI Container's click method\n  Button(onClick = { this.onClick() }) { Text(\"Github Sign-In (Custom Design)\") }\n}\n\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirzemehdi%2FKMPAuth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmirzemehdi%2FKMPAuth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmirzemehdi%2FKMPAuth/lists"}