Git Product home page Git Product logo

web3auth-android-sdk's Introduction

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 24 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)

        // Call initialize function to get private key and user information value without relogging in user if a user has an active session
        val sessionResponse: CompletableFuture<Void> = web3Auth.initialize()
        sessionResponse.whenComplete { _, error ->
            if (error == null) {
                println("PrivKey: " + web3Auth.getPrivkey())
                println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
                println("Web3Auth UserInfo" + web3Auth.getUserInfo())
            } else {
                // render error UI
            }
        }
        
        // ...
    }
    
    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 { _, error ->
            if (error == null) {
                // render logged in UI
                println("PrivKey: " + web3Auth.getPrivkey())
                println("ed25519PrivKey: " + web3Auth.getEd25519PrivKey())
                println("Web3Auth UserInfo" + web3Auth.getUserInfo())
            } else {
                // render login error UI
            }

        }
    }
    
    //...
}

๐Ÿฉน Examples

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

๐ŸŒ 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 Support

  • Have a look at our Community Portal to see if anyone has any questions or issues you might be having. Feel free to reate new topics and we'll help you out as soon as possible.
  • Checkout our Troubleshooting Documentation Page to know the common issues and solutions.
  • For Priority Support, please have a look at our Pricing Page for the plan that suits your needs.

web3auth-android-sdk's People

Contributors

grvgoel81 avatar chaitanyapotti avatar phuctm97 avatar tanujgupta avatar gaurav-android avatar ayushbherwani1998 avatar michaellee8 avatar yashovardhan avatar sleeptimegrt avatar arch1995 avatar wiyarmir avatar shahbaz17 avatar himanshuchawla009 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.