Before using the SDK, please provide the OIDC JWT verifier to OpenWeb3 so that we can register your application,you need to perform the initialization setup. Follow these steps to initialize the SDK:
Auth
import io.openweb3.plugins.PLUGIN_OPEN_PLATFORM
import io.openweb3.plugins.openplatform.miniapp.IAppDelegate
import io.openweb3.plugins.PluginsManager
import io.openweb3.plugins.openplatform.OpenPlatformPlugin
val openPlatformPlugin = PluginsManager.getPlugin<OpenPlatformPlugin>(PLUGIN_OPEN_PLATFORM)!!
openPlatformPlugin.auth( context = this,
verifier = "123",
idTokenProvider = { idTokenProvider() },
onVerifierSuccess = {
// Do Something
},
onVerifierFailure = { code, message ->
Log.e("Sample", "Verifier Err, code= $code, message: $message")
})
private suspend fun idTokenProvider(): String = suspendCoroutine { continuation -> run {
continuation.resume("eyJhbGciOiJSUzI1NiIsImtpZCI6IjM5ZTg2YmMxYjBjMjI5NDBkNDRjZjNmNWI4NWZmZWYwYTZjNmQzNzIiLCJ0eXAiOiJKV1QifQ.eyJ1aWQiOiJtdHNvY2lhbEBnbWFpLmNvbSIsImlzcyI6ImZpcmViYXNlLWFkbWluc2RrLTR2ejMwQG10c29jaWFsLmlhbS5nc2VydmljZWFjY291bnQuY29tIiwiZXhwIjoxNzUxODEzMTUxLCJpYXQiOjE3MjA3MDkxNTEsImF1ZCI6Imh0dHBzOi8vaWRlbnRpdHl0b29sa2l0Lmdvb2dsZWFwaXMuY29tL2dvb2dsZS5pZGVudGl0eS5pZGVudGl0eXRvb2xraXQudjEuSWRlbnRpdHlUb29sa2l0Iiwic3ViIjoiZmlyZWJhc2UtYWRtaW5zZGstNHZ6MzBAbXRzb2NpYWwuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20ifQ.IxKdRdKZhbiYIbRd7nzieti--cEHNA-65rg01Wl6h64cXVviPlZ5MsaueN4uRUODtYs6mdYMAteoy54Wi0GMJzIGMkClUJtbWTOfW1L43YdB4R4XhhVsx2gvF8iCF0MQrDB8ekfyWEqbBdJdbM0BUH0NjSl1Mg15Ta-Rx1cYsk41vmDULpkqHJl93Xjuu2ts1KY7Rs3kNp1NAj9-gC4kHzUG57dmvLqteb4qMmUN7h2tq_np3rdGUBRzxB_YBOnqICAmJ-u6knV_XT08Ep1fB-H_HqR41W_FMgv3EW-V5pApDddJttNjaTy8rJfy2xL9mOhQV0OH-1vHjm4Mz2Jpeg")
}}
In the above code, we use PluginsManager.getPlugin(PLUGIN_OPEN_PLATFORM) to obtain the singleton instance of the OpenPlatformPlugin and call the auth method for initialization. You need to provide the following parameters:
- context: The application context object.
- verifier: JWT verifier
- idTokenProvider: JWT token Provider
- onVerifierSuccess: Triggered when the installation succeeds
- onVerifierFailure: Triggered when the installation fails
Setup
val miniAppService = openPlatformPlugin.getMiniAppService()
val appConfig = AppConfig.Builder(
context = this,
appName = "Sample",
webAppName = "OpenWeb3",
miniAppHost = listOf("https://openweb3.io","https://t.me"),
appDelegate = this
)
.languageCode("en")
.isDark(false)
.maxCachePage(5)
.resourcesProvider(null)
.floatWindowSize(90, 159)
.build()
miniAppService.setup(config = appConfig)
In the above code, we use openPlatformPlugin.getMiniAppService() to obtain the singleton instance of the MiniAppService and call the setup method for initialization. You need to provide the following parameters:
- context: The application context object.
- appName: Your application name.
- webAppName: Your WebApp Name
- miniAppHost: The list of mini program hosts.
- languageCode: Language code (optional, default: "en").
- isDark: Whether to use a dark theme (optional, default: false).
- maxCachePage: The maximum number of cached mini-app.
- resourcesProvider: Instance of a custom resources provider (optional).
- appDelegate: Instance of a custom application delegate (optional).