Skip to content

Commit

Permalink
Merge pull request #931 from Web3Auth/android-docs
Browse files Browse the repository at this point in the history
[Android PnP SDK] Revamp docs
  • Loading branch information
yashovardhan authored Oct 3, 2024
2 parents 016e556 + 57f80eb commit 75421cd
Show file tree
Hide file tree
Showing 11 changed files with 472 additions and 681 deletions.
301 changes: 166 additions & 135 deletions docs/sdk/pnp/android/custom-authentication.mdx

Large diffs are not rendered by default.

116 changes: 4 additions & 112 deletions docs/sdk/pnp/android/initialize.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,13 @@ However, Initialization is a two-step process:
1. [Creating a Web3Auth Instance](#create-web3auth-instance)
2. [Setting a Result URL](#set-result-url)

## Create Web3Auth Instance

Please note that these are the most critical steps where you must pass on different parameters
according to the preference of your project. Additionally, You must configure Whitelabeling and
Custom Authentication within this step if you wish to customize your Web3Auth Instance.

## Create Web3Auth Instance

In your activity, create a `Web3Auth` instance with your Web3Auth project's configurations.

```kotlin
web3Auth = Web3Auth(Web3AuthOptions)
```

### Arguments

#### `Web3AuthOptions`
### Parameters

The Web3Auth Constructor takes an object with `Web3AuthOptions` as input.

Expand Down Expand Up @@ -80,112 +72,12 @@ data class Web3AuthOptions(
```

</TabItem>

</Tabs>

### Instance
### Initialize Web3Auth

<Initialization />

### Session Management

The Session Management feature allows you to check the existing sessions with Web3Auth. The
`sessionResponse()` will allow users to remain authenticated with Web3Auth for up to 1 day default,
or a maximum of 7 days, or until they logout or session data is cleared. To change the default
session time, you can pass `sessionTime` in `Web3AuthOptions`.

```kotlin
// Call sessionResponse() in onCreate() to check for any existing session.
val sessionResponse: CompletableFuture<Void> = web3Auth.initialize()
sessionResponse.whenComplete { _, error ->
if (error == null) {
Log.d("MainActivity_Web3Auth", "User already logged in")
// Add your logic
} else {
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
// Ideally, you should initiate the login function here.
}
}
```

:::note

If you're looking for `refreshToken` to maintain the JWT session, use this method instead to extend
the session.

:::

## Set Result URL

<SetResultUrl />

## Example

```kotlin
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 = Network.MAINNET,
redirectUrl = Uri.parse("{YOUR_APP_PACKAGE_NAME}://auth")
)
)

// Handle user signing in when app is not alive
web3Auth.setResultUrl(intent?.data)

// Calls sessionResponse() to check for any existing session.
val sessionResponse: CompletableFuture<Void> = web3Auth.initialize()
sessionResponse.whenComplete { _, error ->
if (error == null) {
Log.d("MainActivity_Web3Auth", "User already logged in")
// Add your logic
} else {
Log.d("MainActivity_Web3Auth", error.message ?: "Something went wrong")
// Ideally, you should initiate the login function here.
}
}

// Setup UI and event handlers
val signInButton = findViewById<Button>(R.id.signInButton)
signInButton.setOnClickListener { signIn() }
}

override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)

// Handle user signing in when app is active
web3Auth.setResultUrl(intent?.data)
}

private fun signIn() {
val selectedLoginProvider = Provider.GOOGLE // Can be GOOGLE, FACEBOOK, TWITCH etc.
val loginCompletableFuture: CompletableFuture<Web3AuthResponse> =
web3Auth.login(LoginParams(selectedLoginProvider))

loginCompletableFuture.whenComplete { loginResponse, error ->
if (error == null) {
// render logged in UI
println(loginResponse)
} else {
// render error UI
}
}
}
//...
}
```

:::tip sample app

Get started with a
[sample application found here](/examples?product=Plug+and+Play&sdk=Plug+and+Play+Android+SDK).

:::
17 changes: 10 additions & 7 deletions docs/sdk/pnp/android/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ import Whitelist from "@site/src/common/sdk/pnp/android/_android-whitelist.mdx";
import Deeplinking from "@site/src/common/sdk/pnp/android/_android-deep-linking.mdx";
import ManifestChanges from "@site/src/common/sdk/pnp/android/_android-manifest-changes.mdx";

## Add Web3Auth to Gradle
## Installation

<UpdateGradle />

Then, in your app-level `build.gradle` dependencies section, add the following:

<Installation />

### Permissions
## Update Permissions

<AndroidPermissions />

## Configuration
## Configure AndroidManifest File

### Configure a Plug n Play project
<ManifestChanges />

<Whitelist />
## Configuration Redirection

### Configure AndroidManifest File
Once the gradles and permission has been updated, you need to configure Web3Auth project by
whitelisting your scheme and package name.

<ManifestChanges />
### Configure a Plug n Play project

<Whitelist />

### Configure Deep Link

Expand Down
Loading

0 comments on commit 75421cd

Please sign in to comment.