https://github.com/ethanblake4/exponentcore
The core library of Exponent, a set of Android utilities for accessing private Google APIs.
https://github.com/ethanblake4/exponentcore
android android-library google login
Last synced: about 2 months ago
JSON representation
The core library of Exponent, a set of Android utilities for accessing private Google APIs.
- Host: GitHub
- URL: https://github.com/ethanblake4/exponentcore
- Owner: ethanblake4
- Created: 2018-11-18T08:35:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-03-14T07:15:44.000Z (over 5 years ago)
- Last Synced: 2025-03-28T20:13:09.593Z (about 1 year ago)
- Topics: android, android-library, google, login
- Language: Kotlin
- Homepage:
- Size: 501 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ExponentCore
This is the core library of Exponent, a set of Android utilities for accessing private Google APIs. Standalone, it provides comprehensive support for authentication via reimplementation of Play Services methods, including support for multi-factor/2-factor authentication. It offers both high-level and low-level APIs for interacting directly with Play Services at any skill level.
Exponent is written in Kotlin and has library dependencies on the Kotlin stdlib, AppCompat v7, and OkHttp.
Exponent has *no dependency* on Play Services (or microG etc.) being installed on a target device, so it's also great for open-source apps intended for custom ROMs. However, support for public Google APIs is currently nonexistent (feel free to open an issue).
To use Exponent in your project, simply add the following line to your app module's build.gradle:
`implementation 'io.ethanblake4:exponent-core:0.0.1'`
### Initialization
Before using any of the below methods, make sure to call `Exponent.init(context)`. A good place to put it is in your Application subclass, but it can go anywhere as long as it is called before any other Exponent method.
## AuthFlow Authentication
Exponent provides a high-level API, AuthFlow, that creates and manages the entire authentication process, including UI and multi-factor authentication, with minimal effort. To use AuthFlow, call the `ExAuthFlow.start` method from within your Activity or Fragment:
```kotlin
class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loginButton.setOnClickListener {
ExAuthFlow.start(this@MyActivity, ExAuthFlow.Format.WEB_AUTH, { loginState ->
if(loginState == ExAuthFlow.State.COMPLETE) {
// Auth complete. Do something!
Log.d("My First Name", ExponentAccounts.currentAccount!!.firstName)
}
}, { throwable ->
Toast.makeText(this@MyActivity, "Error logging in", Toast.LENGTH_LONG).show();
})
}
}
}
```
## One Level Down: ExponentAccounts
If you want to implement a custom authentication UI, ExponentAccounts is still a fairly high level API that manages login, persistence, and service tokens. It's highly encouraged to use it in concert with `AutoMFA` to enable multi-factor authentication. Here's the example from above, modified to use ExponentAccounts:
```kotlin
class MyActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
loginButton.setOnClickListener {
// You'll have to prompt the user for these on your own
val email = emailTextField.text
val password = passwordTextField.text
ExponentAccounts.login(email, password, { accountInfo ->
// Auth complete. Do something!
Log.d("My First Name", accountInfo.firstName)
}, { throwable ->
// Did this error happen because the user has MFA? If so, we can use AutoMFA to recover!
if(throwable is NeedsBrowserException) {
// Use AutoMFA to recover
AutoMFA.handleBrowserRecover(this@MyActivity, email, throwable, { accountInfo ->
// Auth complete. Do something!
Log.d("My First Name", accountInfo.firstName)
}, { err ->
Toast.makeText(this@MyActivity, "Error logging in", Toast.LENGTH_LONG).show();
})
} else {
Toast.makeText(this@MyActivity, "Error logging in", Toast.LENGTH_LONG).show();
}
})
}
}
}
```