Whatsapp Based Login
Try this to implement fastest phone number verification system [
Verify your phone number through whatsapp android
Before Proceeding Further
Please go to this link and follow the steps to setup server for whatsapp verification
Link to Server RepoNow Let's Proceed Further
Gradle
Add the JitPack repo to your project's build.gradle
file:
maven { url 'https: //jitpack.io' }
Add the dependency below to your module's build.gradle
file:
dependencies {
implementation 'com.github.Piyusinha:WhatsappBasedLogin:v1.0.1'
}
How to Use
WhatsAppBasedLogin supports both Kotlin and Java projects, so you can reference it by your language.
Create WhatsappLogin with Kotlin DSL
WaVerifySdk.WASdkBuilder(
context,
businessnumber,
socketUrl )
.callback(whatsappLoginCallback) \\ optional
.message(message) \\ optional
.jwtSecretKey(key) \\ required if you are not using our default key
.build()
Here, whatsappLoginCallback is an interface that you need to define in your app where you would get the success or failure callbacks
Note : Use same businessnumber which you verify on Meta for Developers Portal
Default JWT secret key = "accesstokensecretaccesstokensecr" (lenght must be greater the 32 )
You can trigger the Whatsapp verification flow by calling the following method
GlobalScope.launch {
WaVerifySdk.getInstance()?.verifyOtpService()
}
Note: Socket Runs on Background Thread so calling this method require Coroutine Scope.
Implements Callback
val whatsappLoginCallback: WhatsappLoginCallback = object : WhatsappLoginCallback {
override fun onWhatsAppLoginSuccess(success: WASuccessResponse?) {
this@MainActivity.runOnUiThread({
findViewById<TextView>(R.id.textView)?.text = success?.name
})
}
override fun onWhatsAppError(exception: Throwable) {
}
}
Callback coming from Background thread so it's important to pass it to main thread
Clearing SDK instance (Important)
override fun onDestroy() {
super.onDestroy()
WaVerifySdk.getInstance()?.onDestroy()
}
Note: It's important to Destory SDK instance beacause it's close the socket connection.
Check whatsapp present in User's device or not
You can check if the Whatsapp app is present on the user's device or not by using the following method
WaVerifySdk.getInstance().isUsable()
License
Copyright 2022 lucifer (Piyush Sinha)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.