Plaid Link IOS sample app errorMessage: "link_token must be properly formatted, non-empty string",

1k Views Asked by At

I cloned https://github.com/plaid/plaid-link-ios plaid's IOS sample swift app and followed the instructions for Plaid node to get a Generated token. https://plaid.com/docs/quickstart/

I put my token in the swift app linkToken variable in the func presentPlaidLinkUsingLinkToken() but when I run the app and click on the plaid link I'm presented with this error:

2020-11-30 18:03:07.629202-0600 LinkDemo-Swift[1378:41715] [] nw_protocol_get_quic_image_block_invoke dlopen libquic failed 2020-11-30 18:03:08.771021-0600 LinkDemo-Swift[1378:41497] WF: === Starting WebFilter logging for process LinkDemo-Swift 2020-11-30 18:03:08.771106-0600 LinkDemo-Swift[1378:41497] WF: _userSettingsForUser : (null) 2020-11-30 18:03:08.771167-0600 LinkDemo-Swift[1378:41497] WF: _WebFilterIsActive returning: NO 2020-11-30 18:03:08.997682-0600 LinkDemo-Swift[1378:41497] Unbalanced calls to begin/end appearance transitions for <LinkKit.InProcessWebviewFallbackController: 0x13fe30a70>. exit with ExitError(errorCode: LinkKit.ExitErrorCode.invalidRequest(INVALID_FIELD), errorMessage: "link_token must be properly formatted, non-empty string", displayMessage: Optional(""), errorJSON: nil) ExitMetadata(status: Optional(requires_credentials), institution: Optional(LinkKit.Institution(id: "", name: "")), linkSessionID: Optional(""), requestID: Optional("FzibHWAqJqtTG3e"), metadataJSON: nil) 2020-11-30 18:03:40.762780-0600 LinkDemo-Swift[1378:41497] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service 2020-11-30 18:03:40.768987-0600 LinkDemo-Swift[1378:41497] Could not signal service com.apple.WebKit.Networking: 113: Could not find specified service

My token is in the right format I'm sure, I'm not sure what I'm doing wrong.

Please help,

Thanks

2

There are 2 best solutions below

0
On

Following the steps below I was able to build and run the LinkDemo-Swift app in iOS Simulator (iPhone 12 mini iOS 14.2) and link an account using the sandbox test credentials.

To ensure there are no mismatches in the environment the following commands show which setup I have used:

% sw_vers
ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H15
% xcode-select -p
/Applications/Xcode.app/Contents/Developer
% xocdebuild -version
Xcode 12.2
Build version 12B45b
% swift -version
Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin19.6.0
% git -C $PATH_TO/quickstart log --format=oneline -1; true # replace $PATH_TO with the path to the directory containing the Plaid quickstart git clone
 9ccc96567eaec7a77209676a1693387cc93a32d0 (HEAD -> master, upstream/master, upstream/HEAD) Merge pull r equest #167 from plaid/sb-quickstart-improvements
% git -C $PATH_TO/plaid-link-ios log --format=oneline -1; true # replace $PLAID_TO with the path to the directory containing the plaid-link-ios git clone
 0a8b0c4a85d6042fafdb5deaa346d41364cafc1f (HEAD -> master, tag: ios/2.0.8, origin/master, origin/HEAD)  Merge pull request #38 from plaid/add-changelog-2.0.8

Additionally I have the following Plaid quickstart related environment variables set (values redacted):

% env | grep -Ei '^plaid_(client_id|secret|public_key)' | tr 'a-z0-9' '•'
PLAID_CLIENT_ID=••••••••••••••••••••••••
PLAID_SECRET=••••••••••••••••••••••••••••••
PLAID_PUBLIC_KEY=••••••••••••••••••••••••••••••

To generate a link token I ran the node quickstart in Docker

% cd $PATH_TO/quickstart/node
% make QUICKSTART=node up

and also ran the node quickstart locally using nvm (not at the same time as both bind to localhost:8000):

% cd $PATH_TO/quickstart/node
% nvm use; node --version; npm --version
Now using node v14.15.0 (npm v6.14.8)
v14.15.0
6.14.8
% npm install

> [email protected] postinstall $HOME/src/quickstart/node/node_modules/nodemon
> node bin/postinstall || exit 0

added 179 packages from 133 contributors and audited 179 packages in 2.903s

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
% node index.js
plaid-quickstart server listening on port 8000

I used curl to generate a new link token from the node quickstart as follows:

% curl -sX POST localhost:8000/api/create_link_token \
  | awk -F: 'BEGIN{RS=","} /link_token/{print $2}' \
  | pbcopy

With the generated link token in the pasteboard I've replaced the <#GENERATED_LINK_TOKEN#> placeholder in the source code with the actual token:

% cd $PATH_TO/plaid-link-ios
% sed -i "" -e "s/\"<#GENERATED_LINK_TOKEN#>\"/$(pbpaste)/" LinkDemo-Swift/LinkDemo-Swift/ViewController+LinkToken.swift
% git diff -U1 | sed -e '/^\+.*linkToken/s/[0-9]/•/g'; true # link-token redacted
diff --git a/LinkDemo-Swift/LinkDemo-Swift/ViewController+LinkToken.swift b/LinkDemo-Swift/LinkDemo-Swift/ViewController+LinkToken.swift
index 9cce64f..361916a 100644
--- a/LinkDemo-Swift/LinkDemo-Swift/ViewController+LinkToken.swift
+++ b/LinkDemo-Swift/LinkDemo-Swift/ViewController+LinkToken.swift
@@ -20,3 +20,3 @@ extension ViewController {

-        let linkToken = "<#GENERATED_LINK_TOKEN#>"
+        let linkToken = "link-sandbox-f•••ebb•-•d•a-•aa•-adae-••a•••••••••"


I made sure that the sample app is properly configured to use the link token flow:

% grep -i 'let sampleFlow' LinkDemo-Swift/LinkDemo-Swift/ViewController.swift
        let sampleFlow : PlaidLinkSampleFlow = .linkToken

With no further changes to the project and the LinkDemo Xcode workspace open

% open -a Xcode $PATH_TO/plaid-link-ios/LinkDemo.xcworkspace

I was able to "Build and Run (⌘ R)" the LinkDemo-Swift scheme in the iOS Simulator iPhone 12 mini (iOS 14.2 (18B79)) and successfully link an account using the sandbox test credentials user_good pass_good.

If the issue you are seeing persists I recommend to reach out to the official Plaid support (http://dashboard.plaid.com/support/new) providing detailed and exact steps on how the link token was created and which changes to the sample application were made.

0
On

Fwiw, this still works!

I don't have enough creds yet to add a comment, but wanted to share.

Their docs actually get you 90% of the way there. However, as @afh points out, there is another step, which is spinning up the api server. I stopped the Quickstart instance in Docker, but I think you can just assign a diff port in index.js (eg. 8001), launch it, and you'll be fine.