wiyarmir / web3auth-android-sdk

Java/Kotlin seamless logins

Home Page:https://web3auth.io/docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Web3Auth Android SDK

Web3Auth is where passwordless auth meets non-custodial key infrastructure for Web3 apps and wallets. By aggregating OAuth (Google, Twitter, Discord) logins, different wallets and innovative Multi Party Computation (MPC) - Web3Auth provides a seamless login experience to every user on your application.

πŸ“– Documentation

Checkout the official Web3Auth Documentation and SDK Reference to get started!

πŸ’‘ Features

  • Plug and Play, OAuth based Web3 Authentication Service
  • Fully decentralized, non-custodial key infrastructure
  • End to end Whitelabelable solution
  • Threshold Cryptography based Key Reconstruction
  • Multi Factor Authentication Setup & Recovery (Includes password, backup phrase, device factor editing/deletion etc)
  • Support for WebAuthn & Passwordless Login
  • Support for connecting to multiple wallets
  • DApp Active Session Management

...and a lot more

βͺ Requirements

  • Android API version 21 or newer is required.

⚑ Installation

Add Web3Auth to Gradle

In your project-level settings.gradle file, add JitPack repository:

dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
     repositories {
         google()
         mavenCentral()
         maven { url "https://jitpack.io" } // <-- Add this line
     }
}

Then, in your app-level build.gradle dependencies section, add the following:

dependencies {
    // ...
    implementation 'org.torusresearch:web3auth-android-sdk:-SNAPSHOT'
}

Permissions

Open your app's AndroidManifest.xml file and add the following permission:

<uses-permission android:name="android.permission.INTERNET" />

🌟 Configuration

Configure your Web3Auth project

Hop on to the Web3Auth Dashboard and create a new project. Use the Client ID of the project to start your integration.

Web3Auth Dashboard

  • Add {YOUR_APP_PACKAGE_NAME}://auth to Whitelist URLs.

  • Copy the Project ID for usage later.

Configure Deep Link

Open your app's AndroidManifest.xml file and add the following deep link intent filter to your sign-in activity:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <!-- Accept URIs: {YOUR_APP_PACKAGE_NAME}://* -->
    <data android:scheme="{YOUR_APP_PACKAGE_NAME}" />
</intent-filter>

Make sure your sign-in activity launchMode is set to singleTop in your AndroidManifest.xml

<activity
  android:launchMode="singleTop"
  android:name=".YourActivity">
  // ...
</activity>

πŸ’₯ Initialization & Usage

In your sign-in activity', create an Web3Auth instance with your Web3Auth project's configurations and configure it like this:

class MainActivity : AppCompatActivity() {
    // ...
    private lateinit var web3Auth: Web3Auth

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        web3Auth = Web3Auth(
            Web3AuthOptions(context = this,
                clientId = getString(R.string.web3auth_project_id),
                network = Web3Auth.Network.MAINNET,
                redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth"),
                whiteLabel = WhiteLabelData(  // Optional param
                    "Web3Auth Sample App", null, null, "en", true,
                    hashMapOf(
                        "primary" to "#123456"
                    )
                )
            )
        )

        // Handle user signing in when app is not alive
        web3Auth.setResultUrl(intent?.data)
        
        // ...
    }
    
    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)

        // Handle user signing in when app is active
        web3Auth.setResultUrl(intent?.data)

        // ...
    }

    private fun onClickLogin() {
        val selectedLoginProvider = Provider.GOOGLE   // Can be Google, Facebook, Twitch etc
        val loginCompletableFuture: CompletableFuture<Web3AuthResponse> = web3Auth.login(LoginParams(selectedLoginProvider))
        
        loginCompletableFuture.whenComplete { loginResponse, error ->
            if (error == null) {
                // render logged in UI
            } else {
                // render login error UI
            }

        }
    }
    
    //...
}

🩹 Examples

Checkout the examples for your preferred blockchain and platform in our examples repository

🌐 Demo

Checkout the Web3Auth Demo to see how Web3Auth can be used in an application.

Further checkout the app folder within this repository, which contains a sample app.

πŸ’¬ Troubleshooting and Discussions

  • Have a look at our GitHub Discussions to see if anyone has any questions or issues you might be having.
  • Checkout our Troubleshooting Documentation Page to know the common issues and solutions
  • Join our Discord to join our community and get private integration support or help with your integration.

About

Java/Kotlin seamless logins

https://web3auth.io/docs


Languages

Language:Kotlin 100.0%