Callbacks

The most important parts of Spectre API (e.g. Login management) are asynchronous. Applications can poll Spectre API in order to retrieve the updated information.

You can use the Salt Edge Connect without the Mobile SDKs if you wish to. That is not recommended, as you will have to supply your app with functionality already defined in the SDKs.

When you request for a connect token, you can pass an optional argument javascript_callback_type. This argument enables one of the following notification methods:

Salt Edge Connect will send any of these callbacks only in case when javascript_callback_type was specified in the token request.

The callbacks have information about the stage of the login in the state field of the callback. The possible values are as follows:

  • fetching - fetching data is in progress
  • success - a change in the data we store for the login has occured
  • error - an error has occured during fetching process

Requests cycle

To avoid unnecessary requests, performance issues and fetching all data, use the following diagramm:

Iframe injection

When not using the SDKs, your app is responsible for capturing the URLs, if you wish to be notified about the connect process.

The inserted URL has a custom scheme and host. The scheme of the URL is saltbridge and the host is connect. Here’s an example of such a URL: saltbridge://connect/{"data":{"login_id":997674448,"state":"fetching","secret":"Oqws977brjJUfXbEnGqHNsIRl8PytSL60T7JIsRBCZM","custom_fields":{"key":"value"}}}

The URL will be URLEncoded (percent-encoded), the URL above is not URLEncoded to preserve it’s readability.

Once your app has captured the inserted URL, it has to serialize the JSON-encoded URL path following the scheme and the host. Here’s another example, this time of a duplicated login callback:

saltbridge://connect/{"data":{"duplicated_login_id":994317674,"state":"error","custom_fields":{"key":"value"}}}

Once your app has decoded the URL path, it can start performing several actions like accounts listing or error handling.

External Object

If you access the connect page from a .Net host, and you use WebBrowser.ObjectForScripting, Salt Edge will try to call the window.external.SaltBridge function with the login attributes serialized as json:

public void SaltBridge(String serializedLogin) {
  // serializedLogin here looks like this:
  // '{"data":{
  //    "login_id":997674448,
  //    "state":"fetching",
  //    "secret":"Oqws977brjJUfXbEnGqHNsIRl8PytSL60T7JIsRBCZM",
  //    "custom_fields":{"key":"value"}
  //    }
  //  }'
}

Note that in the example above the SaltBridge function is a method defined on the object that was specified as a object for scripting:

webBrowser1.ObjectForScripting = this

which in this case is the object that initialized the web view.

Post message

If you access the connect page wrapped in an iframe, you can use Window.postMessage which performs cross-origin communication:

  window.addEventListener("message", function(event) {
      console.log(JSON.parse(event.data))
    }
  )

  // serializedLogin here looks like this:
  // {
  //   "data": {
  //     "login_id":997674448,
  //     "state":"fetching",
  //     "secret":"Oqws977brjJUfXbEnGqHNsIRl8PytSL60T7JIsRBCZM",
  //     "custom_fields":{"key":"value"}
  //   }
  // }

External Notify

On Windows Store app platform you can use event handler for ScriptNotify event of WebView. Your code should handle window.external.notify(args) call, ScriptNotify will fire and you’ll get the args in Value property of NotifyEventArgs parameter.

Remember to add https://saltedge.com and https://*.saltedge.com to Content URIs in Package.appxmanifest.

protected override void OnNavigatedTo(NavigationEventArgs e) {
  browser.ScriptNotify += browser_ScriptNotify;
}

private void browser_ScriptNotify(object sender, NotifyEventArgs e) {
  var serializedLogin = e.Value;
  // serializedLogin here looks like this:
  // '{"data":{
  //    "login_id":997674448,
  //    "state":"fetching",
  //    "secret":"Oqws977brjJUfXbEnGqHNsIRl8PytSL60T7JIsRBCZM",
  //    "custom_fields":{"key":"value"}
  //    }
  //  }'
}