Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

What do you do with this token?

Fortunately, Connect IQ offers


nonvolatile storage of app properties so you won’t need to re-
authorize each time you run the app. For apps in the Connect IQ
app store, the persistent data is encrypted using a randomly gener‐
ated asymmetric key, and app access is validated with digital signa‐
tures (see the Connect IQ security model). You can use the app
properties to store away the access token you receive from the
server:
// Handle a successful response from the server
function handleResponse(data) {
// Store the access and refresh tokens in properties
// For app store apps the properties are encrypted using
// a randomly generated key
App.getApp().setProperty("refresh_token",
data["refresh_token"]);
App.getApp().setProperty("access_token",
data["access_token"]);
// Store away the athlete id
App.getApp().setProperty("athlete_id",
data["athlete"]["id"]);
// Switch to the data view
Ui.switchToView(new StravaView(), null, Ui.SLIDE_IMMEDIATE);
}
Once you have the access token, you can use it to make authentica‐
ted requests to the server by passing the access token in the HTTP
headers:
Comm.makeWebRequest(
url,
_parameters,
{
:method=>Comm.HTTP_REQUEST_METHOD_GET,
:headers=>{ "Authorization"=>"Bearer " + accessToken }
},
method(:onResponse)
);

Keep It Brief
The Connect IQ Communication API brings the wearable web to
Garmin devices. However, there are some subtleties to how to
expose a web service to a Garmin device. Because all of the commu‐
nication takes place over a Bluetooth Smart connection (you may
know this as Bluetooth LE or BLE), the device is bandwidth limited.
Data transfers through the Connect IQ SDK will have a transfer
speed less than 1 Kb/s, generally between 400 and 800 bytes/s. For

Working with an Authenticated Web Service | 55

You might also like