io.github.jmseb3:hellogin-github

HelLogin Library


Keywords
compose, compose-multiplatform, kotlin, kotlinmultiplatform
License
Apache-2.0

Documentation

Hellogin

This is Compose Multiplatform auth library

This is Development!!

Android IOS
google-Login androidGoogle iOSGoogle
github-Login androidGithub iOSGithub
apple-Login androidApple iOSApple

Features

  • ✅ Google Login
  • ✅ Github Login
  • ✅ Apple Login

To be added

  • ❎ Naver Login

Installation

HelLogin is available on Maven Central. In your root project build.gradle.kts file ( or settings.gradle file) add mavenCentral() to repositories.

repositories {
    mavenCentral()
}

Then in your shared module add desired dependencies in commonMain. Latest version: Maven Central Version

sourceSets {
    commonMain.dependencies {
        implementation(platform("io.github.jmseb3:hellogin-bom:1.1.0"))

        implementation("io.github.jmseb3:hellogin-google") //google login library
        implementation("io.github.jmseb3:hellogin-github") //github login library 
        implementation("io.github.jmseb3:hellogin-apple") //apple login library
       // or
        implementation("io.github.jmseb3:hellogin-google-ui") //google login with ui library
        implementation("io.github.jmseb3:hellogin-github-ui") //github login with ui library
        implementation("io.github.jmseb3:hellogin-apple-ui") //apple login with ui library
    }
}

or use toml

[versions]
hellogin = "1.1.0"

[libraries]
hellogin-bom = { module = "io.github.jmseb3:hellogin-bom", version.ref = "hellogin" }

hellogin-google = { module = "io.github.jmseb3:hellogin-google" }
hellogin-github = { module = "io.github.jmseb3:hellogin-github" }
hellogin-apple = { module = "io.github.jmseb3:hellogin-apple" }
// OR
hellogin-google-ui = { module = "io.github.jmseb3:hellogin-google-ui" }
hellogin-github-ui = { module = "io.github.jmseb3:hellogin-github-ui" }
hellogin-apple-ui = { module = "io.github.jmseb3:hellogin-apple-ui" }
sourceSets {
    commonMain.dependencies {
        implementation(project.dependencies.platform(libs.hellogin.bom))

        implementation(libs.hellogin.google)
        implementation(libs.hellogin.github)
        implementation(libs.hellogin.apple)

        implementation(libs.hellogin.google.ui)
        implementation(libs.hellogin.github.ui)
        implementation(libs.hellogin.apple.ui)
    }
}

How To Use

how to use this library

Android

use HelloginContainerProvider.setContainer(this) on Activity onCreate

class AppActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ...
        HelloginContainerProvider.setContainer(this)
    }
}

IOS

use HelloginContainerProvider.setContainer(this) on MainViewController create

fun MainViewController(): UIViewController {
    return ComposeUIViewController { App() }.also {
        HelloginContainerProvider.setContainer(it)
    }
}

Google

don't forget Google Api console setting!!

also default setting

look Android/ IOS

  1. plz install first GoogleOptionProviderper platform

also IOS need GoogeSigin SPM or pods on Your Project

Android

class AppActivity : ComponentActivity(), OptionProviderAndroid {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        ...
        GoogleLoginHelper.setOptionProvider(this)
    }

    override fun provideGoogleIdOption(): GetGoogleIdOption {
        return GetGoogleIdOption.Builder()
            .setFilterByAuthorizedAccounts(false)
            .setServerClientId("WEB_CLIENT_ID")
            .build()
    }

}

use OptionProviderAndroid because need GetGoogleIdOption

IOS

no need any setting for google Login

  1. launch GoogleLoginHelper with TokenResultHandler

No UI

   GoogleLoginHelper.requestLogin(tokenResultHandler) //this is suspend function

Use UI

if use io.github.jmseb3:hellogin-google-ui , GoogleLoginButton()

    GoogleLoginButton()

Github

make Github OAuth Apps and don't forget your GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET

also android need scheme setting .. if callback is hellogin://login then

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

    <application>
        <activity>
            ...
            <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="login" android:scheme="hellogin" />
            </intent-filter>
        </activity>
    </application>

</manifest>
  1. Please install the GitHub provider in the commonMain module (or separately for each platform if needed).

common

internal class GitHubProvider : GithubOptionProvider {
    companion object {
        const val GITHUB_CLIENT_ID = "YOUR_CLIENT_ID"
        const val GITHUB_CLIENT_SECRET = "YOUR_CLIENT_SECRET"
    }

    override fun provideLoginId(): CodeRequestData {
        return CodeRequestData(
            GITHUB_CLIENT_ID
        )
    }

    override fun provideClientData(): ClientData {
        return ClientData(
            GITHUB_CLIENT_ID,
            GITHUB_CLIENT_SECRET
        )
    }

    override fun provideScheme(): String {
        return "hellogin"
    }
}
@Composable
internal fun App() = AppTheme {
    LaunchedEffect(true) {
        GithubLoginHelper.setOptionProvider(GitHubProvider())
    }
    ...
}

Android

class AppActivity : ComponentActivity(), OptionProviderAndroid {
    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        CoroutineScope(Dispatchers.Main).launch {
            intent.data?.getQueryParameter("code")?.let { code ->
                // Get Token By Intent
                GithubLoginHelper.requestAuth(code)
            }
        }
    }
}
  1. launch GithubLoginHelper with TokenResultHandler

No UI

   GithubLoginHelper.requestLogin(tokenResultHandler) // this is suspend function

Use UI

if use io.github.jmseb3:hellogin-github-ui , GithubLoginButton()

    GithubLoginButton()

Apple