Trait libhealth::sync::sync_provider::SyncProvider
source · pub trait SyncProvider {
Show 14 methods
// Required methods
fn api_url(&self) -> &'static str;
fn provider_name(&self) -> &'static str;
fn oauth2_token(
&mut self
) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>;
fn initial_authenticate(&mut self) -> Result<()>;
fn initial_import(&mut self) -> Result<()>;
fn reauthenticate(&mut self) -> Result<()>;
fn sync_data(&mut self) -> Result<()>;
// Provided methods
fn get<T: DeserializeOwned>(&mut self, method: &str) -> Result<T> { ... }
fn post<T: DeserializeOwned>(
&mut self,
method: &str,
data: Value
) -> Result<T> { ... }
fn exchange_refresh_token(
&self,
client: &BasicClient
) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>> { ... }
fn schema(&self) -> Schema { ... }
fn token(&self) -> Result<Option<RefreshToken>> { ... }
fn set_token(&self, value: RefreshToken) -> Result<()> { ... }
fn start_listen_server(
authorize_url: &str
) -> Result<(AuthorizationCode, CsrfToken)> { ... }
}
Expand description
SyncProvider is a trait that should be implemented by all 3rd party providers.
Required Methods§
sourcefn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Returns the name of the provider (which is used for storing it in the keyring).
sourcefn oauth2_token(
&mut self
) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>
fn oauth2_token( &mut self ) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>
Gets the OAuth2 token or reauthenticates with the refresh token if no token has been set yet.
sourcefn initial_authenticate(&mut self) -> Result<()>
fn initial_authenticate(&mut self) -> Result<()>
Perform the initial authentication. This should open the user’s browser so they can authenticate with their provider.
sourcefn initial_import(&mut self) -> Result<()>
fn initial_import(&mut self) -> Result<()>
Start the initial import. This should import all data from the sync provider to the Tracker DB.
sourcefn reauthenticate(&mut self) -> Result<()>
fn reauthenticate(&mut self) -> Result<()>
Exchange the refresh token we already stored for an access token.
Provided Methods§
sourcefn get<T: DeserializeOwned>(&mut self, method: &str) -> Result<T>
fn get<T: DeserializeOwned>(&mut self, method: &str) -> Result<T>
sourcefn exchange_refresh_token(
&self,
client: &BasicClient
) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>
fn exchange_refresh_token( &self, client: &BasicClient ) -> Result<StandardTokenResponse<EmptyExtraTokenFields, BasicTokenType>>
Exchange a refresh token for an access token.
sourcefn token(&self) -> Result<Option<RefreshToken>>
fn token(&self) -> Result<Option<RefreshToken>>
Retrieve the RefreshToken from the secret store.
Returns
A RefreshToken
if a refresh token is set, or None
if no refresh token is set.
May return an error if querying the secret store fails.
sourcefn set_token(&self, value: RefreshToken) -> Result<()>
fn set_token(&self, value: RefreshToken) -> Result<()>
Set the RefreshToken in the secret store.
Arguments
value
- The RefreshToken that should be stored.
Returns
May return an error if querying the secret store fails.
sourcefn start_listen_server(
authorize_url: &str
) -> Result<(AuthorizationCode, CsrfToken)>
fn start_listen_server( authorize_url: &str ) -> Result<(AuthorizationCode, CsrfToken)>
Starts a server which listens for the user to finish authenticating with their OAuth2 provider
and captures the OAuth2 code
once the user is redirect to the server.
Arguments
authorize_url
- The URL which should be opened in the user’s browser so they can authenticate.
Returns
The AuthorizationCode and CsrfToken that were returned by the sync provider, or an error if
reading the response fails. Please keep in mind that the returned CrfsToken
should always be compared
to what you sent to the provider to make sure the request went through fine.