[−][src]Function quarenta::login
pub async fn login<'_, '_, '_, '_>(
client: &'_ Client,
username: &'_ String,
password: &'_ String,
referrer: &'_ String
) -> Result<JsonValue, Box<dyn Error>>
Attempts to login to ArcGIS Online.
Arguments
client
- Areqwest
client. IfNone
, this method creates a new one. It is advisable to create one and reuse it.username
- The usernamepassword
- The passwordreferrer
- A referrer string that will need to be used with the resulting token
Return
The function returns a JSON result which, if Ok
, contains either values for token
,
expires
, and ssl
or an error
object. An invalid username/password combination
results in the error
object.
Errors
The function's result will be either Ok
or Err
. If Err
, it's probably because the login
request went wrong (e.g. no network connectivity), not because of a bad username or password.
Examples
let reqwest_client = reqwest::Client::new(); let login_result: Result<T,Box<dyn Error>> = login(&reqwest_client, &username, &password, &referrer).await; match login_result { Ok(token_response) => { match token_response["token"].as_str() { Some(token) => { println!("Token: {}...", &token[..20]); println!("Expiry: {}", token_response["expires"]); println!("SSL only: {}", token_response["ssl"]); }, None => { println!("Login returned but was not successful: {}", token_response); } } }, Err(err) => { println!("Something went wrong while calling login: {:?}", err); }, }