Data & Customization
Custom Data Source Authorizers
Rover Experiences feature support for REST API data sources, that allow for customizing experience content with JSON data. REST API data sources often need to authorize a request, and the Rover SDK allows you to modify outbound data source HTTP requests to include additional authorization information, including headers and query parameters.
Authentication for api.rover.io is built in
Note that when using one of the data sources provided by Rover at api.rover.io
, the JWT token provided by SDK Authentication is used and no custom authorizers are needed.
Call Rover.shared.authorize()
and specify the hostname of your REST API (you can additionally glob multiple subdomains using asterisk *
for wildcards), and then give a closure that receives a URLRequest
value type that you can modify as needed.
We support asynchronous I/O in the authorizers so if you need to do I/O (such as to fetch or refresh a token), you can do so directly inline with the request.
For example, the following pattern matches both "api.example.com" and "stats.example.com":
*.example.com
.
Swift
Provide a callback closure to the Rover SDK that will be called whenever a request is made to a matching host, and the closure can modify the outbound request as needed:
Rover.shared.authorizeAsync(pattern: "*.example.com") { urlRequest in
// perform whatever async work is necessary to obtain a token, etc.
urlRequest.setValue("mytoken", forHTTPHeaderField: "Authorization")
}
The authorizer callback is marked async
, so if you need to retrieve or refresh a token using asynchronous I/O, you can do so.
Kotlin
Provide a callback closure to the Rover SDK that will be called whenever a request is made to a matching host, and the closure can modify the outbound request as needed:
Rover.shared.authorizeAsync("*.example.com") { urlRequest ->
// perform whatever async work is necessary to obtain a token, etc.
urlRequest.headers["Authorization"] = "mytoken"
}
The authorizer callback is marked suspend
, so if you need to retrieve or refresh a token using asynchronous I/O, you can do so.
URLRequest on Android
On iOS we use the URLRequest
type provided by the Cocoa framework, but on Android we have our own value type in a similar shape. Its task is to describe an outbound request, and offers headers
and url
properties that can be mutated.