pub struct ClientSecrets {
pub client_id: String,
pub project_id: String,
pub auth_uri: String,
pub token_uri: String,
pub auth_provider_x509_cert_url: String,
pub client_secret: String,
pub redirect_uris: Vec<String>,
}Expand description
Representation of the client_secrets JSON file that contains the authorization info for your API.
use drive_v3::ClientSecrets;
use drive_v3::AccessToken;
let secrets_path = "my_secrets.json";
let my_client_secrets = ClientSecrets::from_file(&secrets_path)?;
// Now you can requests access tokens with your client secrets
let scopes = ["https://www.googleapis.com/auth/drive.metadata.readonly"];
let my_access_token = AccessToken::request(&my_client_secrets, &scopes)?;
// After getting your token you can make a request (with reqwest for example) using it for authorization
let client = reqwest::blocking::Client::new();
let body = client.get("google-api-endpoint")
.bearer_auth(&my_access_token.access_token)
.send()?
.text()?;
println!("response: {:?}", body);Fields§
§client_id: StringYour API’s client ID.
project_id: StringYour API’s project ID.
auth_uri: StringThe URI your API can call to request authorization.
token_uri: StringThe URI your API can call to request an AccessToken.
auth_provider_x509_cert_url: StringYour API’s certificate provider URL.
client_secret: StringYour API’s client secret.
redirect_uris: Vec<String>Your API’s redirect URIs.
Implementations§
Source§impl ClientSecrets
impl ClientSecrets
Sourcepub fn from_file<T: AsRef<Path>>(file: T) -> Result<Self>
pub fn from_file<T: AsRef<Path>>(file: T) -> Result<Self>
Gets ClientSecrets from file.
§Examples
use drive_v3::ClientSecrets;
use drive_v3::AccessToken;
let secrets_path = "my_secrets.json";
let my_client_secrets = ClientSecrets::from_file(&secrets_path)?;
// Now you can requests access tokens with your client secrets
let scopes = ["https://www.googleapis.com/auth/drive.metadata.readonly"];
let my_access_token = AccessToken::request(&my_client_secrets, &scopes)?;
// After getting your token you can make a request (with reqwest for example) using it for authorization
let client = reqwest::blocking::Client::new();
let body = client.get("google-api-endpoint")
.bearer_auth(&my_access_token.access_token)
.send()?
.text()?;
println!("response: {:?}", body);§Errors
Requests and authorization code and it’s associated code_verifier from Google’s API.
This code can be used to request AccessTokens using
OAuth2.
§Note:
Do not use this function directly in drive_v3 unless you need to make custom requests using an authorization
code, instead use the Credentials struct to easily handle authorization.
§Examples:
See Google’s official handle OAuth 2.0 responses documentation for information on what to use these codes for.
§Errors
- a
HexDecodingorUrlParsingerror, if the creation of thecode verifierfailed. - a
UrlParsingerror, if the creation of the authorization request’s URL failed. - a
LocalServerorIOerror, if theLocalServerfailed to listen for incoming requests. - a
UrlParsingerror, if unable to get thequerycontaining the returnedauthorization code. - a
MismatchedStateerror, if thestatecontained on the response doesn’t match the originally created one. - a
MismatchedScopeserror, if the user didn’t authorize all the requested scopes. - a
NoAuthorizationCodeerror, if the response didn’t contain anauthorization code.
Trait Implementations§
Source§impl Clone for ClientSecrets
impl Clone for ClientSecrets
Source§fn clone(&self) -> ClientSecrets
fn clone(&self) -> ClientSecrets
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ClientSecrets
Available on non-tarpaulin_include only.
impl Debug for ClientSecrets
tarpaulin_include only.Source§impl<'de> Deserialize<'de> for ClientSecrets
impl<'de> Deserialize<'de> for ClientSecrets
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for ClientSecrets
impl PartialEq for ClientSecrets
Source§impl Serialize for ClientSecrets
impl Serialize for ClientSecrets
impl Eq for ClientSecrets
impl StructuralPartialEq for ClientSecrets
Auto Trait Implementations§
impl Freeze for ClientSecrets
impl RefUnwindSafe for ClientSecrets
impl Send for ClientSecrets
impl Sync for ClientSecrets
impl Unpin for ClientSecrets
impl UnwindSafe for ClientSecrets
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.