mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2025-12-31 16:40:05 +01:00
chore(syntax): Use dyn everywhere to prepare for deprecation.
This commit is contained in:
@@ -44,7 +44,7 @@ pub struct Authenticator<D, S, C> {
|
||||
/// The `api_key()` method is an alternative in case there are no scopes or
|
||||
/// if no user is involved.
|
||||
pub trait GetToken {
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> Result<Token, Box<Error>>
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> Result<Token, Box<dyn Error>>
|
||||
where
|
||||
T: AsRef<str> + Ord + 'b,
|
||||
I: IntoIterator<Item = &'b T>;
|
||||
@@ -87,7 +87,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn do_installed_flow(&mut self, scopes: &Vec<&str>) -> Result<Token, Box<Error>> {
|
||||
fn do_installed_flow(&mut self, scopes: &Vec<&str>) -> Result<Token, Box<dyn Error>> {
|
||||
let installed_type;
|
||||
|
||||
match self.flow_type {
|
||||
@@ -108,7 +108,7 @@ where
|
||||
&mut self,
|
||||
scopes: &Vec<&str>,
|
||||
code_url: String,
|
||||
) -> Result<Token, Box<Error>> {
|
||||
) -> Result<Token, Box<dyn Error>> {
|
||||
let mut flow = DeviceFlow::new(self.client.clone(), &self.secret, &code_url);
|
||||
|
||||
// PHASE 1: REQUEST CODE
|
||||
@@ -121,14 +121,14 @@ where
|
||||
match res_err {
|
||||
RequestError::ClientError(err) => match self.delegate.client_error(&err) {
|
||||
Retry::Abort | Retry::Skip => {
|
||||
return Err(Box::new(StringError::from(&err as &Error)));
|
||||
return Err(Box::new(StringError::from(&err as &dyn Error)));
|
||||
}
|
||||
Retry::After(d) => sleep(d),
|
||||
},
|
||||
RequestError::HttpError(err) => {
|
||||
match self.delegate.connection_error(&err) {
|
||||
Retry::Abort | Retry::Skip => {
|
||||
return Err(Box::new(StringError::from(&err as &Error)));
|
||||
return Err(Box::new(StringError::from(&err as &dyn Error)));
|
||||
}
|
||||
Retry::After(d) => sleep(d),
|
||||
}
|
||||
@@ -159,7 +159,7 @@ where
|
||||
match poll_err {
|
||||
&&PollError::HttpError(ref err) => match self.delegate.client_error(err) {
|
||||
Retry::Abort | Retry::Skip => {
|
||||
return Err(Box::new(StringError::from(err as &Error)));
|
||||
return Err(Box::new(StringError::from(err as &dyn Error)));
|
||||
}
|
||||
Retry::After(d) => sleep(d),
|
||||
},
|
||||
@@ -199,7 +199,7 @@ where
|
||||
/// In any failure case, the delegate will be provided with additional information, and
|
||||
/// the caller will be informed about storage related errors.
|
||||
/// Otherwise it is guaranteed to be valid for the given scopes.
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> Result<Token, Box<Error>>
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> Result<Token, Box<dyn Error>>
|
||||
where
|
||||
T: AsRef<str> + Ord + 'b,
|
||||
I: IntoIterator<Item = &'b T>,
|
||||
|
||||
@@ -77,7 +77,7 @@ pub trait AuthenticatorDelegate {
|
||||
/// This can be useful if the underlying `TokenStorage` may fail occasionally.
|
||||
/// if `is_set` is true, the failure resulted from `TokenStorage.set(...)`. Otherwise,
|
||||
/// it was `TokenStorage.get(...)`
|
||||
fn token_storage_failure(&mut self, is_set: bool, _: &Error) -> Retry {
|
||||
fn token_storage_failure(&mut self, is_set: bool, _: &dyn Error) -> Retry {
|
||||
let _ = is_set;
|
||||
Retry::Abort
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ where
|
||||
auth_delegate: &mut AD,
|
||||
appsecret: &ApplicationSecret,
|
||||
scopes: S,
|
||||
) -> Result<Token, Box<Error>>
|
||||
) -> Result<Token, Box<dyn Error>>
|
||||
where
|
||||
T: AsRef<str> + 'a,
|
||||
S: Iterator<Item = &'a T>,
|
||||
@@ -160,13 +160,13 @@ where
|
||||
auth_delegate: &mut AD,
|
||||
appsecret: &ApplicationSecret,
|
||||
scopes: S,
|
||||
) -> Result<String, Box<Error>>
|
||||
) -> Result<String, Box<dyn Error>>
|
||||
where
|
||||
T: AsRef<str> + 'a,
|
||||
S: Iterator<Item = &'a T>,
|
||||
{
|
||||
let server = self.server.take(); // Will shutdown the server if present when goes out of scope
|
||||
let result: Result<String, Box<Error>> = match server {
|
||||
let result: Result<String, Box<dyn Error>> = match server {
|
||||
None => {
|
||||
let url = build_authentication_request_url(
|
||||
&appsecret.auth_uri,
|
||||
@@ -220,7 +220,7 @@ where
|
||||
appsecret: &ApplicationSecret,
|
||||
authcode: &str,
|
||||
custom_redirect_uri: Option<String>,
|
||||
) -> Result<JSONTokenResponse, Box<Error>> {
|
||||
) -> Result<JSONTokenResponse, Box<dyn Error>> {
|
||||
let redirect_uri = custom_redirect_uri.unwrap_or_else(|| match &self.server {
|
||||
None => OOB_REDIRECT_URI.to_string(),
|
||||
Some(server) => format!("http://localhost:{}", server.port),
|
||||
@@ -263,7 +263,7 @@ where
|
||||
|
||||
match token_resp {
|
||||
Result::Err(e) => return Result::Err(Box::new(e)),
|
||||
Result::Ok(tok) => Result::Ok(tok) as Result<JSONTokenResponse, Box<Error>>,
|
||||
Result::Ok(tok) => Result::Ok(tok) as Result<JSONTokenResponse, Box<dyn Error>>,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -338,14 +338,15 @@ impl std::ops::Drop for InstalledFlowServer {
|
||||
|
||||
pub struct InstalledFlowHandlerResponseFuture {
|
||||
inner: Box<
|
||||
futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error> + Send,
|
||||
dyn futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error> + Send,
|
||||
>,
|
||||
}
|
||||
|
||||
impl InstalledFlowHandlerResponseFuture {
|
||||
fn new(
|
||||
fut: Box<
|
||||
futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error> + Send,
|
||||
dyn futures::Future<Item = hyper::Response<hyper::Body>, Error = hyper::http::Error>
|
||||
+ Send,
|
||||
>,
|
||||
) -> Self {
|
||||
Self { inner: fut }
|
||||
|
||||
@@ -47,7 +47,7 @@ fn encode_base64<T: AsRef<[u8]>>(s: T) -> String {
|
||||
base64::encode_config(s.as_ref(), base64::URL_SAFE)
|
||||
}
|
||||
|
||||
fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKey, Box<error::Error>> {
|
||||
fn decode_rsa_key(pem_pkcs8: &str) -> Result<PrivateKey, Box<dyn error::Error>> {
|
||||
let private = pem_pkcs8.to_string().replace("\\n", "\n").into_bytes();
|
||||
let mut private_reader: &[u8] = private.as_ref();
|
||||
let private_keys = pemfile::pkcs8_private_keys(&mut private_reader);
|
||||
@@ -122,7 +122,7 @@ impl JWT {
|
||||
head
|
||||
}
|
||||
|
||||
fn sign(&self, private_key: &str) -> Result<String, Box<error::Error>> {
|
||||
fn sign(&self, private_key: &str) -> Result<String, Box<dyn error::Error>> {
|
||||
let mut jwt_head = self.encode_claims();
|
||||
let key = decode_rsa_key(private_key)?;
|
||||
let signing_key = sign::RSASigningKey::new(&key)
|
||||
@@ -237,7 +237,10 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn request_token(&mut self, scopes: &Vec<&str>) -> result::Result<Token, Box<error::Error>> {
|
||||
fn request_token(
|
||||
&mut self,
|
||||
scopes: &Vec<&str>,
|
||||
) -> result::Result<Token, Box<dyn error::Error>> {
|
||||
let mut claims = init_claims_from_key(&self.key, scopes);
|
||||
claims.sub = self.sub.clone();
|
||||
let signed = JWT::new(claims).sign(self.key.private_key.as_ref().unwrap())?;
|
||||
@@ -311,7 +314,7 @@ impl<C: 'static> GetToken for ServiceAccountAccess<C>
|
||||
where
|
||||
C: hyper::client::connect::Connect,
|
||||
{
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> result::Result<Token, Box<error::Error>>
|
||||
fn token<'b, I, T>(&mut self, scopes: I) -> result::Result<Token, Box<dyn error::Error>>
|
||||
where
|
||||
T: AsRef<str> + Ord + 'b,
|
||||
I: IntoIterator<Item = &'b T>,
|
||||
|
||||
@@ -99,8 +99,8 @@ impl StringError {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a Error> for StringError {
|
||||
fn from(err: &'a Error) -> StringError {
|
||||
impl<'a> From<&'a dyn Error> for StringError {
|
||||
fn from(err: &'a dyn Error) -> StringError {
|
||||
StringError::new(err.description().to_string(), None)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user