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

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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

web3auth-android-sdk's Issues

debug reinstall crash

kotlin.UninitializedPropertyAccessException: lateinit property sharedPreferences has not been initialized
at com.web3auth.session_manager_android.keystore.KeyStoreManager.savePreferenceData(KeyStoreManager.kt:127)
at com.web3auth.session_manager_android.SessionManager.saveSessionId(SessionManager.kt:54)
at com.web3auth.core.Web3Auth.setResultUrl(Web3Auth.kt:120)

Compilation error if my app has its own Application class in manifest

Hey, my android app has Application class and I can't use 3.0.0 SDK because it has Application class too.

Heres the compilation error:

Error:
	Attribute application@name value=(com.xxx.xxx.xxx) from AndroidManifest.xml:13:9-47
	is also present at [org.torusresearch:web3auth-android-sdk:3.0.0] AndroidManifest.xml:17:18-62 value=(com.web3auth.core.Web3AuthApp).
	Suggestion: add 'tools:replace="android:name"' to <application> element at AndroidManifest.xml:9:5-105:19 to override.

LogOut never seems to actually complete

Coming over from the using the Flutter SDK -
We seem to be seeing some odd behaviour with the logout on a project

It seems that the logout completable future will never actually complete, meaning that if we're awaiting it over on the flutter side, it'll never actually return.
The problem seems to be here

if (web3AuthResponse.privKey.isNullOrBlank()) {

If I understand the code correctly, the setResultUrl, is supposed to check if the private key is null or blank (ie or ``)

However, the response I seem to be getting from the logout function is with an auth which when decoded gives me

{"privKey":"0000000000000000000000000000000000000000000000000000000000000000","sessionId":"","ed25519PrivKey":"0000000000000000000000000000000000000000000000000000000000000000[load of chars which are not 0s removed just in case]","userInfo":{}}

thus not being blank or null, and thus causing the setResultUrl for the logout completable future to be skipped.

SAMSUNG Galaxy S20+Login Google Error

SAMSUNG Galaxy S20+ login google success after error,Error is as follows:
"Could not get result from torus nodes Unable to resolve enough promises”

Caused by com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException:

I follow this guide using Firebase with Web3Auth
So It can work well however only occurs a crash happens in Galaxy S20 5G device (Android 13)

Below is my code and error log.

  1. implement web3auth-android-sdk:3.3.0
implement org.torusresearch:web3auth-android-sdk:3.3.0
  1. I initiated the web3auth
 private val web3Auth: Web3Auth by lazy {
        val options = Web3AuthOptions(
            context = requireContext(),
            clientId = getString(R.string.web3auth_project_id),
            network = Web3Auth.Network.TESTNET,
            redirectUrl = //..
            loginConfig = hashMapOf(
                "jwt" to LoginConfigItem(
                    verifier = //..
                    typeOfLogin = TypeOfLogin.JWT,
                    name = "Firebase Login",
                    clientId = getString(R.string.web3auth_project_id)
                )
            )
        )
        Web3Auth(options)
    }
  1. It occur crash when web3Auth calls the setResultUrl
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initView()
        initButton()
        web3Auth.setResultUrl(activity?.intent?.data) 
        activity?.addOnNewIntentListener(onNewIntentListener)
    }

This is a crash log.

Caused by com.google.crypto.tink.shaded.protobuf.InvalidProtocolBufferException: Protocol message contained an invalid tag (zero).
       at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1036)
       at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1028)
       at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeUnknownField(ArrayDecoders.java:1028)
       at com.google.crypto.tink.shaded.protobuf.MessageSchema.parseProto3Message(MessageSchema.java:5426)
       at com.google.crypto.tink.shaded.protobuf.MessageSchema.mergeFrom(MessageSchema.java:5442)
       at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeMessageField(ArrayDecoders.java:246)
       at com.google.crypto.tink.shaded.protobuf.ArrayDecoders.decodeMessageList(ArrayDecoders.java:704)
       at com.google.crypto.tink.shaded.protobuf.MessageSchema.parseProto3Message(MessageSchema.java:5373)
       at com.google.crypto.tink.shaded.protobuf.MessageSchema.mergeFrom(MessageSchema.java:5442)
       at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parsePartialFrom(GeneratedMessageLite.java:1567)
       at com.google.crypto.tink.shaded.protobuf.GeneratedMessageLite.parseFrom(GeneratedMessageLite.java:1680)
       at com.google.crypto.tink.proto.Keyset.parseFrom(Keyset.java:958)
       at com.google.crypto.tink.integration.android.SharedPrefKeysetReader.read(SharedPrefKeysetReader.java:84)
       at com.google.crypto.tink.CleartextKeysetHandle.read(CleartextKeysetHandle.java:61)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.read(AndroidKeysetManager.java:332)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.readOrGenerateNewKeyset(AndroidKeysetManager.java:288)
       at com.google.crypto.tink.integration.android.AndroidKeysetManager$Builder.build(AndroidKeysetManager.java:239)
       at androidx.security.crypto.EncryptedSharedPreferences.create(EncryptedSharedPreferences.java:169)
       at com.web3auth.core.keystore.KeyStoreManagerUtils.initializePreferences(KeyStoreManagerUtils.kt:39)
       at com.web3auth.core.Web3Auth.<init>(Web3Auth.kt:72)

getting weird error in building

so after migrating to 4.0.8, while building I get this :
Can't determine type for tag '?attr/shapeAppearanceCornerSmall'

why is that? how to handle that? i tried to change some important libraries but it didn't change anything, so what is going on?

please upgrade security-crypto to "1.1.0-alpha04"

web3auto-android-sdk:3.2.0 depends on protobuf-lite:3.0.1 that last updated at Jul 28, 2016。
image
Google : Use Java Protocol Buffers on Android
For Android users, it's recommended to use protobuf Java Lite runtime because of its smaller code size. Java Lite runtime also works better with Proguard because it doesn't rely on Java reflection and is optimized to allow as much code stripping as possible. You can following these instructions to use Java Lite runtime.

The latest version of security-crypto:1.1.0-alpha04 depens on the latest version of think-android:1.7.0 that remove protobuf-lite。

so, please upgrade security-crypto to "1.1.0-alpha04"。

init exception

AndroidRuntime: FATAL EXCEPTION: main
java.lang.ExceptionInInitializerError
at com.web3auth.core.Web3Auth.initiateKeyStoreManager(Web3Auth.kt:83)
at com.web3auth.core.Web3Auth.(Web3Auth.kt:59)

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.