react-native-background-geolocation
react-native-background-geolocation copied to clipboard
[Question] Precision about JWT implementation
Your Environment
- Plugin version: 4.14.5
- Platform: iOS & Android
- OS version: -
- Device manufacturer / model: -
- React Native version (
react-native -v): - Plugin config
ReactNativeBackgroundGeolocation.ready(
{
debug: isDev,
logLevel: isDev
? ReactNativeBackgroundGeolocation.LogLevel.verbose
: ReactNativeBackgroundGeolocation.LogLevel.off,
stopOnTerminate: false,
startOnBoot: true,
maxRecordsToPersist: 2,
distanceFilter: ReactNative.Platform.os === #ios ? 50 : 0, // The iOS CLLocationManager API is strictly distance-based. see https://github.com/transistorsoft/react-native-background-geolocation/wiki/Philosophy-of-Operation#distance-based-tracking
enableTimestampMeta: true,
isMoving: true,
maxDaysToPersist: 1,
batchSync: true,
autoSyncThreshold: 2,
httpRootProperty: "coords",
locationTemplate: "{\"latitude\":<%= latitude %>,\"longitude\":<%= longitude %>,\"geocodedAt\":\"<%= timestamp %>\"}",
// ios
preventSuspend: true,
stationaryRadius: 25, // minimum possible read: https://transistorsoft.github.io/react-native-background-geolocation/interfaces/config.html#stationaryradius
// android
foregroundService: true,
enableHeadless: false,
allowIdenticalLocations: true,
locationUpdateInterval: 1000 * 60,
fastestLocationUpdateInterval: 1000 * 60,
notification: {
text: "Livraison(s) en cours",
},
url: apiUrl,
authorization: {
strategy: "JWT",
accessToken: accessToken->Option.getWithDefault(""),
refreshToken: refreshToken->Option.getWithDefault(""),
refreshUrl: `${env.urls.auth}/refreshToken`,
refreshPayload: {
refreshToken: "{refreshToken}"
},
},
params: {
"deliveriesIds": trackableDeliveryIds,
},
}
)
Expected Behavior
When the plugin receives a 401 status code from the url configured with the "JWT" strategy, a refresh attempt is made with the other refresh fields configured.
Actual Behavior
The request is sent but how the plugin handle the new data ?
The new token sent by the refreshToken API are stored by plugin for himself or should we (as developers) handle the storage through the onAuthorization event.
My authentication API returns a new token, my guess by reading the documentation is the plugin expect the authentication API to renew the same token validity is that right ?
Thanks for your help.
The request is sent but how the plugin handle the new data ?
The plugin analyzes the returned JSON response, performing regular-expressions upon the keys and automatically updates your Config.authorization using the discovered data in the response. You do not need to do anything in onAuthorization.
"access token": ^(access|auth)
"refresh token": ^(refresh|renew)
Eg 1:
{
"access_token": "<your token>",
"refresh_token":"<your refresh token>"
}
Eg 2
{
"accessToken": "<your token>",
"refreshToken":"<your refresh token>"
}
Eg 2
{
"auth_token": "<your token>",
"renew_token":"<your refresh token>"
}
Thanks for the clarification.
I tried to implement this and I have an odd Java error in the logs
Is it from the request initiated by the plugin reading some invalid data or the data response sent by the API ?
Thanks for your help.
Your refreshUrl is returning <html>, not JSON.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.