Authorization strategy. Only JWT is supported.
Authorization token (eg: JWT) required for authorization by your server at HttpConfig.url.
The SDK will automatically apply the configured accessToken to each HTTP request's Authorization header, eg:
"Authorization": "Bearer XXX.YYY.ZZZ"
You do not need to manually configure HttpConfig.headers with the Authorization parameter. It is all automatic.
OptionalrefreshThe token to be POSTed to refreshUrl, encoded into the refreshPayload, when a new accessToken is required after expires or when HTTP 401 Unauthorized is received.
OptionalrefreshThe url to your authorization server that provides new accessToken when expired.
When the SDK receives a response the server, it will decode the JSON and recursively iterate through the keys, performing regular expressions and other String-analysis to "taste" the data in search of the following 3 items:
The SDK is designed to operate with any response data-structure. For example, one authorization server might return a complex response such as:
{
"token": {
"access_token": "XXX.YYY.ZZZ",
"expires_at": 3900
},
"refresh_token": "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb"
}
While another server might return a flat response, such as:
{
"accessToken": "XXX.YYY.ZZZ",
"refreshToken": "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb",
"expiry": 3900
}
When the response from the server is received, the event BackgroundGeolocation.onAuthorization will be fired, provided with the AuthorizationEvent.
OptionalrefreshRefresh payload will be encoded into the FORM POST to the refreshUrl when requesting a new accessToken after expiration.
You must provide one field-template which will represent your "refresh token" using the value: {refreshToken}. The SDK will
automatically replace this simple template with the configured refreshToken.
BackgroundGeolocation.ready({
authorization: {
strategy: "JWT",
accessToken: "XXX.YYY.ZZZ",
refreshUrl: "https://auth.your.server.com/tokens",
refreshToken: "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb",
refreshPayload: {
my_refresh_token: "{refreshToken}",
grant_type: "refresh_token",
foo: "another arbitrary field"
}
}
});
with the configuration above, a curl representation of the SDK's FORM POST, might look like this:
$ curl -X POST \
-F 'my_refresh_token=smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb' \
-F 'grant_type=refresh_token' \
-F 'foo=another arbitrary field' \
https://auth.your.server.com/tokens
OptionalrefreshOptional headers applied on requests to refreshUrl
Defaults to: {"Authorization": "Bearer {accessToken}"}
The template variable {accessToken} will automatically be replaced with your app's current auth token.
If you do not want any headers applied on requests to {refreshUrl}, provide an empty {}.
BackgroundGeolocation.ready({
authorization: {
accessToken: "XXX.YYY.ZZZ",
refreshUrl: "https://auth.domain.com/tokens",
refreshToken: "smTsfaspfgaadsfgqZerUt0wueflasdfkaxjdfeKIacb",
refreshPayload: {
"my_refresh_token": "{refreshToken}", // <-- replaced with configured refreshToken above.
"grant_type": "refresh_token", // <-- arbitrary fields required by your auth server
"foo": "another arbitrary field"
},
refreshHeaders: {} // <-- Empty {} to provide no refreshHeaders.
)
));
OptionalexpiresToken expiry time in seconds.
Configure the SDK to authenticate with your server using an access token (e.g., a JSON Web Token), and automatically request new tokens when the server returns
401 Unauthorized.Note: Only JSON Web Token (JWT) is currently supported.
The SDK automatically attaches your token to each HTTP request:
When using Config.authorization, do not manually define
Authorizationinside HttpConfig.headers. The SDK manages all JWT headers automatically.If you supply AuthorizationConfig.refreshUrl, AuthorizationConfig.refreshToken, and AuthorizationConfig.refreshPayload, the SDK can automatically refresh expired tokens when a
401 Unauthorizedresponse is received.Configuration
Example
Receiving responses from AuthorizationConfig.refreshUrl
Whenever the SDK receives a response from your refreshUrl, it fires BackgroundGeolocation.onAuthorization. Your callback will receive an AuthorizationEvent.
Example