Open login flow in in-app browser for native (WIP)

zio/stable
Paul Frazee 2022-06-14 20:29:24 -05:00
parent 5066f3ba81
commit b2dd8d4f44
5 changed files with 95 additions and 43 deletions

View File

@ -291,6 +291,8 @@ PODS:
- React-perflogger (= 0.68.2)
- RNCAsyncStorage (1.17.6):
- React-Core
- RNInAppBrowser (3.6.3):
- React-Core
- RNScreens (3.13.1):
- React-Core
- React-RCTImage
@ -331,6 +333,7 @@ DEPENDENCIES:
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- RNInAppBrowser (from `../node_modules/react-native-inappbrowser-reborn`)
- RNScreens (from `../node_modules/react-native-screens`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
@ -403,6 +406,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon"
RNCAsyncStorage:
:path: "../node_modules/@react-native-async-storage/async-storage"
RNInAppBrowser:
:path: "../node_modules/react-native-inappbrowser-reborn"
RNScreens:
:path: "../node_modules/react-native-screens"
Yoga:
@ -442,9 +447,10 @@ SPEC CHECKSUMS:
React-runtimeexecutor: b960b687d2dfef0d3761fbb187e01812ebab8b23
ReactCommon: 095366164a276d91ea704ce53cb03825c487a3f2
RNCAsyncStorage: 466b9df1a14bccda91da86e0b7d9a345d78e1673
RNInAppBrowser: 3ff3a3b8f458aaf25aaee879d057352862edf357
RNScreens: 40a2cb40a02a609938137a1e0acfbf8fc9eebf19
Yoga: 99652481fcd320aefa4a7ef90095b95acd181952
PODFILE CHECKSUM: b316ed22d303852bcbc21555181e167a3972828b
PODFILE CHECKSUM: cf94853ebcb0d8e0d027dca9ab7a4ede886a8f20
COCOAPODS: 1.11.3

View File

@ -26,10 +26,11 @@
"react": "17.0.2",
"react-dom": "17.0.2",
"react-native": "0.68.2",
"react-native-inappbrowser-reborn": "^3.6.3",
"react-native-safe-area-context": "^4.3.1",
"react-native-screens": "^3.13.1",
"react-native-web": "^0.17.7",
"ucans": "0.9.0-alpha3"
"ucans": "0.9.1"
},
"devDependencies": {
"@adxp/auth-lobby": "*",

View File

@ -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
} else {
// TODO
console.log('TODO')
}
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 {
Linking.openURL(url)
}
return true
}

View File

@ -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}`
}
}

View File

@ -3,9 +3,9 @@
"@adxp/auth-lobby@*":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@adxp/auth-lobby/-/auth-lobby-0.0.1.tgz#3ee32295efb6d977b366682178185d9ea716da5d"
integrity sha512-7+tduabTJtQKCFbniiVnZt7sOgOg4Pd2qxXoDS+VPmajIs9MVRMVL4T8F0fI3LAvhXs2a1lUNTluMz0Tro6GtQ==
version "0.0.2"
resolved "https://registry.yarnpkg.com/@adxp/auth-lobby/-/auth-lobby-0.0.2.tgz#3098f16d6357fea447be4e1e06b8befc39035846"
integrity sha512-qXcbKzXp3skHjui3stLkoR8nm+ohp80MJ/rlktNbpHYqYbjJrNLeu3eskEBxQYTmtt9hQV5bbhSyIpn0WMc3IQ==
dependencies:
"@adxp/auth" "*"
"@adxp/awake" "*"
@ -2626,14 +2626,14 @@
integrity sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==
"@types/node@*", "@types/node@>=10.0.0":
version "17.0.42"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.42.tgz#d7e8f22700efc94d125103075c074396b5f41f9b"
integrity sha512-Q5BPGyGKcvQgAMbsr7qEGN/kIPN6zZecYYABeTDBizOsau+2NMdSVTar9UQw21A2+JyA2KRNDYaYrPB0Rpk2oQ==
version "17.0.43"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.43.tgz#7f16898cdd791c9d64069000ad448b47b3ca8353"
integrity sha512-jnUpgw8fL9kP2iszfIDyBQtw5Mf4/XSqy0Loc1J9pI14ejL83XcCEvSf50Gs/4ET0I9VCCDoOfufQysj0S66xA==
"@types/node@^16.11.36":
version "16.11.39"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.39.tgz#07223cd2bc332ad9d92135e3a522eebdee3b060e"
integrity sha512-K0MsdV42vPwm9L6UwhIxMAOmcvH/1OoVkZyCgEtVu4Wx7sElGloy/W7kMBNe/oJ7V/jW9BVt1F6RahH6e7tPXw==
version "16.11.40"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.40.tgz#bcf85f3febe74436107aeb2d3fb5fd0d30818600"
integrity sha512-7bOWglXUO6f21NG3YDI7hIpeMX3M59GG+DzZuzX2EkFKYUnRoxq3EOg4R0KNv2hxryY9M3UUqG5akwwsifrukw==
"@types/normalize-package-data@^2.4.0":
version "2.4.1"
@ -5172,9 +5172,9 @@ dns-equal@^1.0.0:
integrity sha512-z+paD6YUQsk+AbGCEM4PrOXSss5gd66QfcVBFTKR/HpFL9jCqikS94HYwKww6fQyO7IxrIIyUu+g0Ka9tUS2Cg==
dns-packet@^5.2.2:
version "5.3.1"
resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.3.1.tgz#eb94413789daec0f0ebe2fcc230bdc9d7c91b43d"
integrity sha512-spBwIj0TK0Ey3666GwIdWVfUpLyubpU53BTCu8iPn4r4oXd9O14Hjg3EHw3ts2oed77/SeckunUYCyRlSngqHw==
version "5.4.0"
resolved "https://registry.yarnpkg.com/dns-packet/-/dns-packet-5.4.0.tgz#1f88477cf9f27e78a213fb6d118ae38e759a879b"
integrity sha512-EgqGeaBB8hLiHLZtp/IbaDQTL8pZ0+IvwzSHA6d7VyMDM+B9hgddEMa9xjK5oYnw0ci0JQ6g2XCD7/f6cafU6g==
dependencies:
"@leichtgewicht/ip-codec" "^2.0.1"
@ -5303,9 +5303,9 @@ ejs@^3.1.6:
jake "^10.8.5"
electron-to-chromium@^1.4.147:
version "1.4.154"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.154.tgz#d69c60499fc467a6c59591d29183e520afbc78a1"
integrity sha512-GbV9djOkrnj6xmW+YYVVEI3VCQnJ0pnSTu7TW2JyjKd5cakoiSaG5R4RbEtfaD92GsY10DzbU3GYRe+IOA9kqA==
version "1.4.155"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.155.tgz#9c7190bf5e8608c5a5e4953b1ccf0facf3d1b49d"
integrity sha512-niPzKBSYPG06gxLKO0c2kEmgdRMTtIbNrBlvD31Ld8Q57b/K0218U4j8u/OOt25XE1eFOn47FcmQVdx9R1qqxA==
emittery@^0.10.2:
version "0.10.2"
@ -5663,9 +5663,9 @@ eslint-plugin-prettier@3.1.2:
prettier-linter-helpers "^1.0.0"
eslint-plugin-react-hooks@^4.0.4, eslint-plugin-react-hooks@^4.3.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.5.0.tgz#5f762dfedf8b2cf431c689f533c9d3fa5dcf25ad"
integrity sha512-8k1gRt7D7h03kd+SAAlzXkQwWK22BnK6GKZG+FJA6BAGy22CFvl8kCIXKpVux0cCxMWDQUPqSok0LKaZ0aOcCw==
version "4.6.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-4.6.0.tgz#4c3e697ad95b77e93f8646aaa1630c1ba607edd3"
integrity sha512-oFc7Itz9Qxh2x4gNHStv3BqJq54ExXmfC+a1NjAta66IAN87Wu0R/QArgIS9qKzX3dXKPI9H5crl9QchNMY9+g==
eslint-plugin-react-native-globals@^0.1.1:
version "0.1.2"
@ -9789,6 +9789,11 @@ open@^8.0.9, open@^8.4.0:
is-docker "^2.1.1"
is-wsl "^2.2.0"
opencollective-postinstall@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz#7a0fff978f6dbfa4d006238fbac98ed4198c3259"
integrity sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==
optionator@^0.8.1:
version "0.8.3"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.3.tgz#84fa1d036fe9d3c7e21d99884b601167ec8fb495"
@ -10969,12 +10974,12 @@ react-dom@17.0.2:
scheduler "^0.20.2"
react-dom@^18.1.0:
version "18.1.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.1.0.tgz#7f6dd84b706408adde05e1df575b3a024d7e8a2f"
integrity sha512-fU1Txz7Budmvamp7bshe4Zi32d0ll7ect+ccxNu9FlObT605GOEB8BfO4tmRJ39R5Zj831VCpvQ05QPBW5yb+w==
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==
dependencies:
loose-envify "^1.1.0"
scheduler "^0.22.0"
scheduler "^0.23.0"
react-error-overlay@^6.0.11:
version "6.0.11"
@ -10992,9 +10997,9 @@ react-freeze@^1.0.0:
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0:
version "18.1.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.1.0.tgz#61aaed3096d30eacf2a2127118b5b41387d32a67"
integrity sha512-Fl7FuabXsJnV5Q1qIOQwx/sagGF18kogb4gpfcG4gjLBWO0WDiiz1ko/ExayuxE7InyQkBLkxRFG5oxY6Uu3Kg==
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b"
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==
react-is@^16.13.0, react-is@^16.13.1:
version "16.13.1"
@ -11016,6 +11021,14 @@ react-native-gradle-plugin@^0.0.6:
resolved "https://registry.yarnpkg.com/react-native-gradle-plugin/-/react-native-gradle-plugin-0.0.6.tgz#b61a9234ad2f61430937911003cddd7e15c72b45"
integrity sha512-eIlgtsmDp1jLC24dRn43hB3kEcZVqx6DUQbR0N1ABXGnMEafm9I3V3dUUeD1vh+Dy5WqijSoEwLNUPLgu5zDMg==
react-native-inappbrowser-reborn@^3.6.3:
version "3.6.3"
resolved "https://registry.yarnpkg.com/react-native-inappbrowser-reborn/-/react-native-inappbrowser-reborn-3.6.3.tgz#12938733e5337a9f328973557da0cfd13085bfbd"
integrity sha512-fqF708GVZ/7zja0/GyJQfjDfKREOe1fxYq8RAKZo8/KK6SkFO9hBlYqC3PwLFPw29zzwBzR+6EpL3qo95igkLw==
dependencies:
invariant "^2.2.4"
opencollective-postinstall "^2.0.2"
react-native-safe-area-context@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/react-native-safe-area-context/-/react-native-safe-area-context-4.3.1.tgz#5cf97b25b395e0d09bc1f828920cd7da0d792ade"
@ -11180,9 +11193,9 @@ react@17.0.2:
object-assign "^4.1.1"
react@^18.1.0:
version "18.1.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.1.0.tgz#6f8620382decb17fdc5cc223a115e2adbf104890"
integrity sha512-4oL8ivCz5ZEPyclFQXaNksK3adutVS8l2xzZU0cqEFrE9Sb7fC0EFK5uEk74wIreL1DERyjvsU915j1pcT2uEQ==
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
dependencies:
loose-envify "^1.1.0"
@ -11619,10 +11632,10 @@ scheduler@^0.20.2:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler@^0.22.0:
version "0.22.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.22.0.tgz#83a5d63594edf074add9a7198b1bae76c3db01b8"
integrity sha512-6QAm1BgQI88NPYymgGQLCZgvep4FyePDWFpXVK+zNSUgHwlqpJy8VEh8Et0KxTACS4VWwMousBElAZOH9nkkoQ==
scheduler@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
integrity sha512-CtuThmgHNg7zIZWAXi3AsyIzA3n4xx7aNyjwC2VJldO2LMVDhFK+63xGqq6CsJH4rTAt6/M+N4GhZiDYPx9eUw==
dependencies:
loose-envify "^1.1.0"
@ -12797,7 +12810,7 @@ ucans@0.9.0-alpha3:
tweetnacl "^1.0.3"
uint8arrays "^3.0.0"
ucans@^0.9.1:
ucans@0.9.1, ucans@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/ucans/-/ucans-0.9.1.tgz#d4ed0ed61d11ef13925512d365b26c5c9451b852"
integrity sha512-Vr2z5cy3YcPDhK9RY5VOfoqrXEml3GmZCGovFhLOIVji5PPiR/pkA2ME9jGWqLBQ1mj3494aBjxcMu4DreaAcg==