Skip to content

Commit

Permalink
Fix android 401
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfrouin committed Oct 30, 2023
1 parent d236eb2 commit 66dc3e5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 30 deletions.
26 changes: 2 additions & 24 deletions android/src/main/java/com/reactnativecommunity/webview/RNCGigya.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,21 @@ class RNCGigya(context: Application) {
Gigya.setApplication(context)
}

fun prepare(apiKey: String, apiDomain: String) {
fun initialize(apiKey: String, apiDomain: String, webview: WebView) {
gigya = Gigya.getInstance(GigyaAccount::class.java)
gigya.init(apiKey, apiDomain)
}

fun initialize(sessionToken: String, sessionSecret: String, webview: WebView) {
attachBridge(webview)
logUser(sessionToken = sessionToken, sessionSecret = sessionSecret)
}

private fun logUser(sessionToken: String, sessionSecret: String) {
fun login(sessionToken: String, sessionSecret: String) {
val session = SessionInfo(sessionSecret, sessionToken)
gigya.setSession(session)
}


private fun attachBridge(webview: WebView) {
var webBridge: IGigyaWebBridge<GigyaAccount>? = null

/*
Make sure you enable javascript for your WebView instance.
*/
val webSettings = webview.settings
webSettings.javaScriptEnabled = true

webBridge = gigya.createWebBridge()
webBridge?.attachTo(webview, object: GigyaPluginCallback<GigyaAccount>() {}, null)

/*
Make sure to attach the GigyaWebBridge to your WebViewClient instance.
*/
webview.webViewClient = (object: WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
val uri = request?.url
val uriString = uri.toString()
return webBridge?.invoke(uriString) ?: false
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,14 @@ class RNCWebViewManagerImpl {
gigyaCredentials = RNCGigyaCredentials(sessionToken, sessionSecret, apiKey, apiDomain)

if (gigyaCredentials.sessionToken != null && gigyaCredentials.sessionSecret != null && gigyaCredentials.apiKey != null && gigyaCredentials.apiDomain != null) {
viewWrapper.webView.gigya.prepare(
viewWrapper.webView.gigya.initialize(
gigyaCredentials.apiKey,
gigyaCredentials.apiDomain
gigyaCredentials.apiDomain,
viewWrapper.webView
)
viewWrapper.webView.gigya.initialize(
viewWrapper.webView.gigya.login(
gigyaCredentials.sessionToken,
gigyaCredentials.sessionSecret,
viewWrapper.webView
gigyaCredentials.sessionSecret
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Martin Frouin <[email protected]>"
],
"license": "MIT",
"version": "13.6.7",
"version": "13.6.8",
"homepage": "https://github.com/derniercri/react-native-gigya-webview#readme",
"scripts": {
"android": "react-native run-android",
Expand Down

0 comments on commit 66dc3e5

Please sign in to comment.