-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lucas Frossard
committed
Oct 20, 2023
0 parents
commit 4c55bac
Showing
29 changed files
with
2,318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"project_id" : "wa-otp-android-sdk", | ||
"conduit_uri" : "https://phabricator.fb.com/api/", | ||
"arc.land.onto.default" : "master" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sdk/build/ | ||
.gradle/ | ||
.idea/ | ||
local.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"capabilities": [ | ||
"apply", | ||
"submit", | ||
"suggest", | ||
], | ||
"project_id": "wa-otp-android-sdk" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Code of Conduct | ||
|
||
## Our Pledge | ||
|
||
In the interest of fostering an open and welcoming environment, we as | ||
contributors and maintainers pledge to make participation in our project and | ||
our community a harassment-free experience for everyone, regardless of age, body | ||
size, disability, ethnicity, sex characteristics, gender identity and expression, | ||
level of experience, education, socio-economic status, nationality, personal | ||
appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
|
||
Examples of behavior that contributes to creating a positive environment | ||
include: | ||
|
||
* Using welcoming and inclusive language | ||
* Being respectful of differing viewpoints and experiences | ||
* Gracefully accepting constructive criticism | ||
* Focusing on what is best for the community | ||
* Showing empathy towards other community members | ||
|
||
Examples of unacceptable behavior by participants include: | ||
|
||
* The use of sexualized language or imagery and unwelcome sexual attention or | ||
advances | ||
* Trolling, insulting/derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or electronic | ||
address, without explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a | ||
professional setting | ||
|
||
## Our Responsibilities | ||
|
||
Project maintainers are responsible for clarifying the standards of acceptable | ||
behavior and are expected to take appropriate and fair corrective action in | ||
response to any instances of unacceptable behavior. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or | ||
reject comments, commits, code, wiki edits, issues, and other contributions | ||
that are not aligned to this Code of Conduct, or to ban temporarily or | ||
permanently any contributor for other behaviors that they deem inappropriate, | ||
threatening, offensive, or harmful. | ||
|
||
## Scope | ||
|
||
This Code of Conduct applies within all project spaces, and it also applies when | ||
an individual is representing the project or its community in public spaces. | ||
Examples of representing a project or community include using an official | ||
project e-mail address, posting via an official social media account, or acting | ||
as an appointed representative at an online or offline event. Representation of | ||
a project may be further defined and clarified by project maintainers. | ||
|
||
This Code of Conduct also applies outside the project spaces when there is a | ||
reasonable belief that an individual's behavior may have a negative impact on | ||
the project or its community. | ||
|
||
## Enforcement | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior may be | ||
reported by contacting the project team at <[email protected]>. All | ||
complaints will be reviewed and investigated and will result in a response that | ||
is deemed necessary and appropriate to the circumstances. The project team is | ||
obligated to maintain confidentiality with regard to the reporter of an incident. | ||
Further details of specific enforcement policies may be posted separately. | ||
|
||
Project maintainers who do not follow or enforce the Code of Conduct in good | ||
faith may face temporary or permanent repercussions as determined by other | ||
members of the project's leadership. | ||
|
||
## Attribution | ||
|
||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, | ||
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html | ||
|
||
[homepage]: https://www.contributor-covenant.org | ||
|
||
For answers to common questions about this code of conduct, see | ||
https://www.contributor-covenant.org/faq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Contributing to WhatsApp-Android-OTP-SDK | ||
We want to make contributing to this project as easy and transparent as | ||
possible. | ||
|
||
## Pull Requests | ||
We actively welcome your pull requests. | ||
|
||
1. Fork the repo and create your branch from `main`. | ||
2. If you've added code that should be tested, add tests. | ||
3. If you've changed APIs, update the documentation. | ||
4. Ensure the test suite passes. | ||
5. Make sure your code lints. | ||
6. If you haven't already, complete the Contributor License Agreement ("CLA"). | ||
|
||
## Contributor License Agreement ("CLA") | ||
In order to accept your pull request, we need you to submit a CLA. You only need | ||
to do this once to work on any of Facebook's open source projects. | ||
|
||
Complete your CLA here: <https://code.facebook.com/cla> | ||
|
||
## Issues | ||
We use GitHub issues to track public bugs. Please ensure your description is | ||
clear and has sufficient instructions to be able to reproduce the issue. | ||
|
||
Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe | ||
disclosure of security bugs. In those cases, please go through the process | ||
outlined on that page and do not file a public issue. | ||
|
||
## License | ||
By contributing to WhatsApp-Android-OTP-SDK, you agree that your contributions will be licensed | ||
under the LICENSE file in the root directory of this source tree. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# WhatsApp OTP Android SDK | ||
|
||
This SDK provides an interface which simplifies integration with WhatsApp clients in order to automatically receive the one time password code on your app. | ||
|
||
## Interfaces | ||
|
||
The class ``WhatsAppOtpHandler`` holds logic that applies when sending an intent to WhatsApp, to do the handshake, as well as for checking for WhatsApp installation. | ||
|
||
### Handshake | ||
|
||
Sending an intent to WhatsApp to do the handshake as described on the [Authentication templates document](https://developers.facebook.com/docs/whatsapp/business-management-api/authentication-templates/) is as simple as: | ||
|
||
``` | ||
WhatsAppOtpHandler whatsAppOtpHandler = new WhatsAppOtpHandler(); | ||
whatsAppOtpHandler.sendOtpIntentToWhatsApp(context); | ||
``` | ||
|
||
This sends the handshake to bot the WhatsApp Consumer app and the WhatsApp Business app. If you want to specify a specific WhatsApp flavor, you can use the provided overloaded function like shown below: | ||
|
||
``` | ||
whatsAppOtpHandler.sendOtpIntentToWhatsApp(context, WhatsAppClientType.CONSUMER); | ||
``` | ||
|
||
When doing the handshake, we recommend you do it with both apps. | ||
|
||
### Checking WhatsApp installation | ||
|
||
We also offer two utility functions app developers can use to decide if they want to offer WhatsApp as a channel option to deliver a one time code. | ||
|
||
To check WhatsApp installation you can use the ``isWhatsAppInstalled`` function. This function will return ``true`` if any WhatsApp client is installed. E.g: | ||
|
||
``` | ||
if(whatsAppOtpHandler.isWhatsAppInstalled(context)) { | ||
// ... do something | ||
} | ||
``` | ||
|
||
Or, if you want to check for a specific WhatsApp installation, you can also use the overloaded function which takes the ``WhatsAppClientType`` as a parameter. | ||
|
||
``` | ||
if(whatsAppOtpHandler.isWhatsAppInstalled(context, WhatsAppClientType.BUSINESS)) { | ||
// ... do something | ||
} | ||
``` | ||
|
||
You can also use ``isWhatsAppOtpHandshakeSupported`` function which checks if the installed version supports the handshake. | ||
|
||
``` | ||
// checks if the installed version supports the handshake | ||
if(whatsAppOtpHandler.isWhatsAppOtpHandshakeSupported(context) { | ||
// ... do something | ||
} | ||
``` | ||
|
||
*as of 21-Sept-2023, all versions are expected support the handshake. | ||
|
||
|
||
### Receiving the code | ||
|
||
Receiving the code from WhatsApp is handled by the ``WhatsAppOtpIncomingIntentHandler`` class. | ||
|
||
|
||
We offer a functional interface that provides the code directly: | ||
|
||
``` | ||
whatsAppOtpIncomingIntentHandler.processOtpCode(intent, | ||
(code) -> { | ||
// ... use the code | ||
}, | ||
(error, exception) -> { | ||
// handle error | ||
}); | ||
``` | ||
|
||
Utility functions are offered if you want to create your own abstraction. The following is a function to extract the code from the WhatsApp intent: | ||
|
||
``` | ||
WhatsAppOtpIncomingIntentHandler whatsAppOtpIncomingIntentHandler = new WhatsAppOtpIncomingIntentHandler(); | ||
String code = whatsAppOtpIncomingIntentHandler.getOtpCodeFromWhatsAppIntent(whatsAppIntent); | ||
``` | ||
|
||
This function throws an ``InvalidWhatsAppOtpIntentException`` if the PendingIntent within the intent is not from WhatsApp. | ||
|
||
Additionally, you can check if the intent came from WhatsApp by using the function | ||
|
||
``` | ||
boolean intentIsFromWhatsApp = whatsAppOtpIncomingIntentHandler.isIntentFromWhatsApp(whatsAppIntent); | ||
``` | ||
|
||
### Receiving debug signals | ||
|
||
Finally, we also offer a similar interface for you to handle error signals which is also described at the [Authentication Templates documentation](https://developers.facebook.com/docs/whatsapp/business-management-api/authentication-templates/). | ||
|
||
The following functional interface is available to handle the debug signals: | ||
|
||
``` | ||
whatsAppOtpIncomingIntentHandler.processOtpDebugSignals(whatsAppIntent, | ||
(code) -> { | ||
// ... use the code | ||
}, | ||
(error, exception) -> { | ||
// handle error | ||
}); | ||
``` | ||
|
||
Or you can create your own abstraction by using the following function: | ||
|
||
``` | ||
DebugSignal debugSignal = whatsAppOtpIncomingIntentHandler.getDebugSignalFromWhatsAppIntent(whatsAppIntent); | ||
``` | ||
|
||
Similar to the function to get the code, this function throws an ``InvalidWhatsAppOtpIntentException`` if the PendingIntent within the intent is not from WhatsApp. | ||
|
||
## License | ||
|
||
WhatsApp OTP Android SDK is [MIT licensed](./LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
plugins { | ||
id 'com.android.library' version '7.4.0' apply false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Project-wide Gradle settings. | ||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8 | ||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true | ||
# AndroidX package structure to make it clearer which packages are bundled with the | ||
# Android operating system, and which are packaged with your app's APK | ||
# https://developer.android.com/topic/libraries/support-library/androidx-rn | ||
android.useAndroidX=true | ||
# Enables namespacing of each library's R class so that its R class includes only the | ||
# resources declared in the library itself and none from the library's dependencies, | ||
# thereby reducing the size of the R class for that library | ||
android.nonTransitiveRClass=true | ||
version=0.1.0 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Thu Aug 17 18:30:07 PDT 2023 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
Oops, something went wrong.