about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/api/auth.ts34
-rw-r--r--src/platform/urls.tsx12
2 files changed, 39 insertions, 7 deletions
diff --git a/src/api/auth.ts b/src/api/auth.ts
index 2da8f2cc7..60ff1a3f2 100644
--- a/src/api/auth.ts
+++ b/src/api/auth.ts
@@ -1,5 +1,8 @@
+import {Linking} from 'react-native'
 import * as auth from '@adxp/auth'
+import {InAppBrowser} from 'react-native-inappbrowser-reborn'
 import {isWeb} from '../platform/detection'
+import {makeAppUrl} from '../platform/urls'
 import * as env from '../env'
 
 const SCOPE = auth.writeCap(
@@ -33,16 +36,33 @@ export async function parseUrlForUcan() {
 
 export async function requestAppUcan(authStore: auth.BrowserStore) {
   const did = await authStore.getDid()
+  const returnUrl = makeAppUrl()
+  const fragment = auth.requestAppUcanHashFragment(did, SCOPE, returnUrl)
+  const url = `${env.AUTH_LOBBY}#${fragment}`
+
   if (isWeb) {
     // @ts-ignore window is defined -prf
-    const redirectTo = window.location.origin
-    const fragment = auth.requestAppUcanHashFragment(did, SCOPE, redirectTo)
-    // @ts-ignore window is defined -prf
-    window.location.href = `${env.AUTH_LOBBY}#${fragment}`
+    window.location.href = url
     return false
+  }
+
+  if (await InAppBrowser.isAvailable()) {
+    const res = await InAppBrowser.openAuth(url, returnUrl, {
+      // iOS Properties
+      ephemeralWebSession: false,
+      // Android Properties
+      showTitle: false,
+      enableUrlBarHiding: true,
+      enableDefaultShare: false,
+    })
+    if (res.type === 'success' && res.url) {
+      Linking.openURL(res.url)
+    } else {
+      console.error('Bad response', res)
+      return false
+    }
   } else {
-    // TODO
-    console.log('TODO')
+    Linking.openURL(url)
   }
-  return false
+  return true
 }
diff --git a/src/platform/urls.tsx b/src/platform/urls.tsx
new file mode 100644
index 000000000..958b5232d
--- /dev/null
+++ b/src/platform/urls.tsx
@@ -0,0 +1,12 @@
+import {isIOS, isAndroid} from './detection'
+
+export function makeAppUrl(path = '') {
+  if (isIOS) {
+    return `pubsqapp://${path}`
+  } else if (isAndroid) {
+    return `pubsq://app${path}`
+  } else {
+    // @ts-ignore window exists -prf
+    return `${window.location.origin}${path}`
+  }
+}