Skip to content

About

Crossly Connect SDK for flutter (partners: https://crossly.net/partners)

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

crossly_connect

Connect a seller's marketplace account (Poshmark, Mercari, Depop, Vinted, …) to Crossly from your Flutter app. The seller signs in inside a WebView whose marketplace traffic goes through that seller's own IP-pinned Crossly proxy, so the session is born on the same IP Crossly later uses it from. OAuth marketplaces open in ASWebAuthenticationSession / the system browser / a Custom Tab instead.

Headless: the widget draws only the WebView. Every header, button, message and loading state is yours, through builders. There is no Crossly branding or copy in the package.

The Flutter twin of @crossly/connect-react-native: same session JSON, same calls, same behaviour.

Partner access: this SDK needs a Crossly partner key (used server-side only). Request access at https://crossly.net/partners.

The rule: no proxy, no login

A marketplace session that is created on the phone's own IP and then used from a server IP is flagged and dies within hours. So this SDK never opens a marketplace login without the proxy:

  • the WebView is created only after the relay route is applied natively (on Android: after ProxyController reports the override in effect);
  • if the device cannot proxy, the relay is missing, the route cannot be applied, the relay keeps refusing its credential or the relay token cannot be renewed, the login does not open (or is closed) and you get onResult(ConnectResultBlocked(reason: ...));
  • there is no fallback to a direct connection, and no option to enable one.

Offer another way to connect (e.g. your desktop extension) when CrosslyConnect.canProxy() says no.

Requirements

iOS iOS 17 or later to connect (WKWebsiteDataStore.proxyConfigurations). The plugin installs on iOS 13+ so your deployment target can stay where it is; below 17, canProxy() answers ios_too_old. Build with Xcode 15+.
Android minSdk 21, and an Android System WebView with PROXY_OVERRIDE and PROXY_OVERRIDE_REVERSE_BYPASS (androidx.webkit). Any current WebView has both; otherwise android_no_proxy_override. The plugin compiles against SDK 35.
Flutter 3.10+ (Dart 3).
Platforms iOS and Android only. Everything else answers unsupported.

The iOS 17 rule

Before iOS 17 there is no public API to route a WKWebView through a proxy, and a private one would not pass App Review. So below iOS 17 there is no login at all, not a degraded one: check canProxy() and show your alternative. Do not lower the bar by opening the marketplace in Safari or a plain WebView yourself; a session born on the phone's IP is worse than no session.

Install

dependencies:
  crossly_connect:
    git:
      url: https://github.com/crossly-dev/crossly-connect-flutter.git
      ref: v0.1.0

(A pub.dev release will follow; then crossly_connect: ^0.1.0 works.)

flutter pub get
cd ios && pod install

No other packages are needed (no webview_flutter, no cookie manager): the plugin carries its own WebView, cookie reader and OAuth opener. Its only Dart dependency is http.

The flow

your server                         Crossly                          your app
-----------                         -------                          --------
POST /v1/partner/sellers/:id/connect-sessions   (partner key)
  { platform: 'poshmark' }   ─────►  provisions the seller's proxy
                             ◄─────  ConnectSession JSON
send the ConnectSession to the app  ──────────────────────────────►  CrosslyConnectView(session: ...)
                                                                      applies the relay, opens the login
                                     POST .../connect-sessions/:id/relay    ◄── renews the relay (upload token)
                                     POST .../connect-sessions/:id/cookies  ◄── signed-in session (upload token)
webhook connection.active  ◄──────  verifies the session server-side
  • Your partner key never goes to the app. The app only receives the ConnectSession; its uploadToken is single-use for /cookies (15 minutes) and reusable for /relay. Both calls send it as Authorization: Bearer <uploadToken>.
  • /cookies gets { cookies: [{ name, value, domain, path, expires? (epoch ms), httpOnly, secure, sameSite }], userAgent }, the user agent being the WebView's own.
  • Create a new ConnectSession for every attempt. A session whose upload token was used or expired cannot be reused.
  • The final word is server-side: GET /v1/partner/connect-sessions/:id or the connection.active / connection.failed webhooks. ConnectResultConnected means the session was handed over.

Usage

import 'package:crossly_connect/crossly_connect.dart';

// Before offering the button at all:
final cap = await CrosslyConnect.canProxy();
if (!cap.ok) showConnectFromComputer(cap.reason!);

// The JSON your server got from POST /v1/partner/sellers/:id/connect-sessions (bare or { data: ... }):
final session = ConnectSession.fromJson(jsonDecode(body) as Map<String, dynamic>);

CrosslyConnectView(
  session: session,
  onResult: (r) {
    switch (r) {
      case ConnectResultConnected():
        showToast('Connected');
      case ConnectResultBlocked(:final reason):
        logReason(reason.wireName);
      case ConnectResultOAuth():
        pollSessionStatus(r.sessionId);
    }
  },
  onError: (err, auto) {
    if (!auto) showToast(err.retryable ? 'Not signed in yet, try again' : 'Start over');
  },
  loadingBuilder: (context) => const MySpinner(),
  blockedBuilder: (context, reason) => MyConnectFromComputer(reason: reason),
  controlsBuilder: (context, state) => MyFooter(
    onDone: state.confirmLoggedIn,
    busy: state.uploading,
  ),
  completeBuilder: (context, result) => const MyDoneState(),
  oauthCallbackUrlScheme: 'myapp', // iOS: OAuth in an ASWebAuthenticationSession returning to myapp://
)

Give the widget bounded constraints (a Scaffold body, an Expanded, a sized box): it fills them with a Column of the WebView and your controls.

API

CrosslyConnect.canProxy() → Future<CanProxyResult>: ok, reason (CanProxyReason.iosTooOld, androidNoProxyOverride, unsupported).

CrosslyConnectView:

Parameter
session The ConnectSession from your server (required). A new session.id starts over.
onResult(r) Once per session. ConnectResultConnected(sessionId, platform, accountId, status, cookieCount) · ConnectResultBlocked(reason) · ConnectResultOAuth(outcome: completed | dismissed | opened, url?).
onError(err, auto) Recoverable problems, CrosslyConnectException with code (noCookies, uploadFailed, relayRenewalFailed, oauthFailed, network), status, serverCode, retryable. auto = raised by automatic detection.
blockedBuilder(context, reason) Shown when the login cannot be opened. BlockedReason: a canProxy reason or relayUnavailable, proxyApplyFailed, relayRenewalFailed.
loadingBuilder(context) Shown while preparing, over the WebView while pages load, and while an OAuth page is open.
controlsBuilder(context, state) Built below the WebView: currentUrl, loggedInDetected, uploading, pageLoading, confirmLoggedIn. Give sellers an "I'm signed in" control calling confirmLoggedIn for when detection misses.
completeBuilder(context, result) Shown after the hand-over (the WebView is gone).
clearCookiesFirst Sign the WebView out of everything first: use for a new account so the previous account's session is not reused. Clears the whole WebView cookie store of your app.
autoDetect Upload as soon as a page matches login.loggedInMatchers (default true).
settle Delay between detection and reading cookies (default 1.5 s).
openAuthSession(url) OAuth sessions: open the page your own way (e.g. flutter_web_auth_2) and return an AuthSessionResult(type: 'success' | 'dismissed' | 'opened', url?).
oauthCallbackUrlScheme OAuth sessions on iOS without openAuthSession: with it, an ASWebAuthenticationSession (outcome completed / dismissed); without it, the system browser (opened). Android always opens a Custom Tab (opened).
userAgent WebView user agent override (default: the WebView's own, which is what is reported).
apiBaseUrl Default https://crossly.net/api.
httpClient Inject an http.Client (tests, custom networking).

Also exported: ConnectSession.fromJson and the other models, isLoggedInUrl / CompiledMatchers, CrosslyConnectApi (the two upload-token calls, if you build your own UI around the native pieces).

login.loggedInMatchers are regular-expression sources tested case-insensitively against each page URL; an entry starting with ! must not match (e.g. ["!login|checkpoint", "facebook\\.com"]). An empty list turns auto-detection off: only confirmLoggedIn uploads.

Behaviour worth knowing

  • Relay renewal. The relay token lives about 15 minutes. The widget renews it through /relay 3 minutes before each expiry (never more often than every 30 s) and re-applies the route; a token already within 30 s of expiry is renewed before the WebView opens. A failed renewal closes the WebView: blocked(relayRenewalFailed).
  • The route. On Android ProxyController applies to every WebView in the process. On iOS every login gets a brand-new non-persistent WKWebsiteDataStore whose proxy is an in-app loopback forwarder (below), set before its one WebView exists, and the store is discarded afterwards; never your app's default store, because WebKit bug 316948 (unfixed in shipped iOS 17/18) keeps a used store's connection pool after a proxy change, so hosts it already reached would go direct. A renewal onto a different relay rebuilds the WebView on a new store. Only the marketplace's hosts are routed (iOS matchDomains, Android reverse bypass); everything else stays direct. The route is cleared when the widget is disposed, blocked or finished, always after the WebView is closed. Do not show another WebView to the same marketplace while CrosslyConnectView is mounted.
  • iOS loopback forwarder. WKWebView's proxy authentication is unreliable (WebKit bug 264309; Apple DTS forum 759417; HTTPS-proxy fixes only in iOS 18), so the WebView never talks to the relay. Each login starts a forwarder inside your app (ios/Classes/ConnectLoopbackForwarder.swift): it listens on 127.0.0.1 on a random port, accepts only CONNECT <marketplace host>:443 for the login's own hosts (403 otherwise, 405 for plain http, at most 32 open tunnels), opens TLS to the Crossly relay and sends the relay token preemptively as Proxy-Authorization: Basic. It never connects anywhere but the relay and stops when the login ends; a renewal swaps its token. The store's proxy is that forwarder: plain CONNECT, no TLS, no credential, matchDomains = the marketplace's hosts. Other apps on the phone can reach a loopback port; the forwarder only ever opens this seller's marketplace hosts, for this login's lifetime. Hardening: each loopback connection must send its CONNECT within 5 s, at most 32 tunnels, and the listener stops the moment the login ends. The forwarder's TLS to the relay is pinned: normal trust evaluation for the relay hostname, then a pinned CA key in the chain (SPKI SHA-256 of ISRG Root X1, X2 and Root YE, the Let's Encrypt chain the relay serves; ConnectForwarderRules.relayCAPins); a chain without one fails closed. The token lives in the forwarder's memory only (never UserDefaults, Keychain or disk) and is never logged. There is no per-login loopback credential: WebKit does not reliably send Proxy-Authorization (bug 264309).
  • Android loopback forwarder. Android WebView cannot authenticate to an HTTPS proxy at all (it never calls onReceivedHttpAuthRequest for one: net::ERR_PROXY_AUTH_UNSUPPORTED), and the relay is one. So the ProxyController rule is http://127.0.0.1:<random port>, a forwarder inside your app (android/.../LoopbackRelayForwarder.kt) with the same rules as on iOS: only CONNECT <marketplace host>:443 for the login's hosts (403 otherwise, 405 for plain http, 503 beyond 32 tunnels), TLS to the relay with the system trust store, hostname verification and the same CA pins (RelayPins, by signature path; rotation steps in the file), the token sent preemptively, never a connection anywhere but the relay, closed with the login. A renewal to the same relay and hosts swaps the token in place.
  • Proxy auth. The relay token never reaches the WebView on either platform. iOS: WebKit never sees a proxy challenge. Android: the forwarder demands its own random per-login credential (SecureRandom) on every CONNECT (407 otherwise), so other apps on the phone cannot use the port, and the plugin's WebView answers that 407 only when it comes from 127.0.0.1 with the forwarder's realm; every other challenge (a marketplace's own basic auth included) is cancelled. If the relay refuses the token 3 times in a row the login is blocked (proxyApplyFailed).
  • Cookies leave the WebView store (Android). After the upload, and whenever the login ends (blocked, disposed), the session's cookies (cookieDomains + the login host) are expired in CookieManager and flushed. iOS drops the login's own store. The upload and relay tokens are only ever in memory.
  • Navigation. Only http(s), about:, data: and blob: load. App links, intent: and custom schemes are refused, so the login cannot escape to an unproxied app or browser. New-window links open in the same WebView.
  • Cookies. Read natively, HttpOnly included: iOS from the login session's own store (httpCookieStore), Android from CookieManager (with full attributes through CookieManagerCompat.getCookieInfo where the WebView supports it, otherwise name/value pairs taken as host-only on the host they were read for). Only cookies of the session's cookieDomains are uploaded.
  • No secret (upload token, relay token, cookie values) is logged or printed by the SDK; the models' toString leave them out. Do not log the ConnectSession JSON yourself.

Why a platform view of our own, not webview_flutter

The SDK needs three things webview_flutter does not give a plugin:

  1. The data store. The iOS route lives on a WKWebsiteDataStore, and it must be a fresh one per login with the route set before the WebView exists. webview_flutter builds its WKWebView internally on a store it picks; the SDK has to create the store itself and know the WebView uses exactly that one.
  2. The proxy challenge. On Android the loopback forwarder's 407 arrives at WebViewClient.onReceivedHttpAuthRequest. webview_flutter's auth callback hands the decision to Dart without a guarantee the WebView is ours alone, and the loopback credential must be answered only to the forwarder (host 127.0.0.1, its realm), natively and synchronously.
  3. Cookies, HttpOnly included. The session cookies are HttpOnly; webview_flutter's cookie manager can set them but not read them. Reading them needs WKHTTPCookieStore.getAllCookies / CookieManager on the same store.

Owning the view also lets the widget close it natively before the route is cleared, so the page cannot reach the marketplace directly in between. The cost is a small native WebView (about 200 lines per platform) instead of a dependency, and no conflict with an app that already uses webview_flutter for other pages.

Device checks

Unit tests (flutter test) cover the matchers, models, relay timing, cookie mapping, the API client and the widget's blocked / OAuth paths. These need real devices before relying on them:

  • iOS 17/18: matchDomains matches subdomains (www.depop.com for depop.com), WebKit reaches the in-app 127.0.0.1 forwarder with no local-network prompt, and tunnels through the live relay complete.
  • Android: the override to http://127.0.0.1:<port> takes effect (no cleartext-policy objection on the loopback hop), the forwarder's 407 reaches onReceivedHttpAuthRequest with host 127.0.0.1 and its realm, the pinned TLS to the live relay verifies, a full login completes, and the cookie purge empties the store.
  • Both: the WebView's first request already goes through the route (applied before the view is created).
  • Both: the session cookies (HttpOnly included) come back for every cookie domain; on Android, whether GET_COOKIE_INFO is available and what its attribute format looks like on current WebView builds.
  • Platform view input: typing in the login form (keyboard, autofill, password managers) inside the Flutter platform view on both platforms.
  • OAuth: ASWebAuthenticationSession returns to the callback scheme; the Custom Tab opens from a non-activity context.

License

MIT

About

Crossly Connect SDK for flutter (partners: https://crossly.net/partners)

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages