mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-02-23 15:50:00 +01:00
deps: update chrono to 0.4
Signed-off-by: Igor Gnatenko <i.gnatenko.brain@gmail.com>
This commit is contained in:
@@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
base64 = "0.9"
|
base64 = "0.9"
|
||||||
chrono = "0.2"
|
chrono = "0.4"
|
||||||
hyper = "0.10.2"
|
hyper = "0.10.2"
|
||||||
hyper-rustls = "0.6.1"
|
hyper-rustls = "0.6.1"
|
||||||
itertools = "0.7"
|
itertools = "0.7"
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use std::error::Error;
|
|||||||
use authenticator::Retry;
|
use authenticator::Retry;
|
||||||
use types::RequestError;
|
use types::RequestError;
|
||||||
|
|
||||||
use chrono::{DateTime, Local, UTC};
|
use chrono::{DateTime, Local, Utc};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
/// Contains state of pending authentication requests
|
/// Contains state of pending authentication requests
|
||||||
@@ -20,7 +20,7 @@ pub struct PollInformation {
|
|||||||
|
|
||||||
/// The `user_code` expires at the given time
|
/// The `user_code` expires at the given time
|
||||||
/// It's the time the user has left to authenticate your application
|
/// It's the time the user has left to authenticate your application
|
||||||
pub expires_at: DateTime<UTC>,
|
pub expires_at: DateTime<Utc>,
|
||||||
/// The interval in which we may poll for a status change
|
/// The interval in which we may poll for a status change
|
||||||
/// The server responds with errors of we poll too fast.
|
/// The server responds with errors of we poll too fast.
|
||||||
pub interval: Duration,
|
pub interval: Duration,
|
||||||
@@ -38,7 +38,7 @@ pub enum PollError {
|
|||||||
/// Connection failure - retry if you think it's worth it
|
/// Connection failure - retry if you think it's worth it
|
||||||
HttpError(hyper::Error),
|
HttpError(hyper::Error),
|
||||||
/// indicates we are expired, including the expiration date
|
/// indicates we are expired, including the expiration date
|
||||||
Expired(DateTime<UTC>),
|
Expired(DateTime<Utc>),
|
||||||
/// Indicates that the user declined access. String is server response
|
/// Indicates that the user declined access. String is server response
|
||||||
AccessDenied,
|
AccessDenied,
|
||||||
}
|
}
|
||||||
@@ -83,7 +83,7 @@ pub trait AuthenticatorDelegate {
|
|||||||
/// Called if the request code is expired. You will have to start over in this case.
|
/// Called if the request code is expired. You will have to start over in this case.
|
||||||
/// This will be the last call the delegate receives.
|
/// This will be the last call the delegate receives.
|
||||||
/// Given `DateTime` is the expiration date
|
/// Given `DateTime` is the expiration date
|
||||||
fn expired(&mut self, &DateTime<UTC>) {}
|
fn expired(&mut self, &DateTime<Utc>) {}
|
||||||
|
|
||||||
/// Called if the user denied access. You would have to start over.
|
/// Called if the user denied access. You would have to start over.
|
||||||
/// This will be the last call the delegate receives.
|
/// This will be the last call the delegate receives.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use hyper::header::ContentType;
|
|||||||
use url::form_urlencoded;
|
use url::form_urlencoded;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
use chrono::{self, UTC};
|
use chrono::{self, Utc};
|
||||||
use std::borrow::BorrowMut;
|
use std::borrow::BorrowMut;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::i64;
|
use std::i64;
|
||||||
@@ -133,7 +133,7 @@ impl<C> DeviceFlow<C>
|
|||||||
let pi = PollInformation {
|
let pi = PollInformation {
|
||||||
user_code: decoded.user_code,
|
user_code: decoded.user_code,
|
||||||
verification_url: decoded.verification_url,
|
verification_url: decoded.verification_url,
|
||||||
expires_at: UTC::now() + chrono::Duration::seconds(decoded.expires_in),
|
expires_at: Utc::now() + chrono::Duration::seconds(decoded.expires_in),
|
||||||
interval: Duration::from_secs(i64::abs(decoded.interval) as u64),
|
interval: Duration::from_secs(i64::abs(decoded.interval) as u64),
|
||||||
};
|
};
|
||||||
self.state = Some(DeviceFlowState::Pending(pi.clone()));
|
self.state = Some(DeviceFlowState::Pending(pi.clone()));
|
||||||
@@ -175,7 +175,7 @@ impl<C> DeviceFlow<C>
|
|||||||
_ => panic!("You have to call request_code() beforehand"),
|
_ => panic!("You have to call request_code() beforehand"),
|
||||||
};
|
};
|
||||||
|
|
||||||
if pi.expires_at <= UTC::now() {
|
if pi.expires_at <= Utc::now() {
|
||||||
self.error = Some(PollError::Expired(pi.expires_at));
|
self.error = Some(PollError::Expired(pi.expires_at));
|
||||||
self.state = Some(DeviceFlowState::Error);
|
self.state = Some(DeviceFlowState::Error);
|
||||||
return Err(&self.error.as_ref().unwrap());
|
return Err(&self.error.as_ref().unwrap());
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use types::{ApplicationSecret, FlowType, JsonError};
|
use types::{ApplicationSecret, FlowType, JsonError};
|
||||||
|
|
||||||
use chrono::UTC;
|
use chrono::Utc;
|
||||||
use hyper;
|
use hyper;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
use serde_json as json;
|
use serde_json as json;
|
||||||
@@ -107,7 +107,7 @@ impl<C> RefreshFlow<C>
|
|||||||
token_type: t.token_type,
|
token_type: t.token_type,
|
||||||
refresh_token: refresh_token.to_string(),
|
refresh_token: refresh_token.to_string(),
|
||||||
expires_in: None,
|
expires_in: None,
|
||||||
expires_in_timestamp: Some(UTC::now().timestamp() + t.expires_in),
|
expires_in_timestamp: Some(Utc::now().timestamp() + t.expires_in),
|
||||||
});
|
});
|
||||||
|
|
||||||
&self.result
|
&self.result
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ fn init_claims_from_key<'a, I, T>(key: &ServiceAccountKey, scopes: I) -> Claims
|
|||||||
where T: AsRef<str> + 'a,
|
where T: AsRef<str> + 'a,
|
||||||
I: IntoIterator<Item = &'a T>
|
I: IntoIterator<Item = &'a T>
|
||||||
{
|
{
|
||||||
let iat = chrono::UTC::now().timestamp();
|
let iat = chrono::Utc::now().timestamp();
|
||||||
let expiry = iat + 3600 - 5; // Max validity is 1h.
|
let expiry = iat + 3600 - 5; // Max validity is 1h.
|
||||||
|
|
||||||
let mut scopes_string = scopes.into_iter().fold(String::new(), |mut acc, sc| {
|
let mut scopes_string = scopes.into_iter().fold(String::new(), |mut acc, sc| {
|
||||||
@@ -179,7 +179,7 @@ struct TokenResponse {
|
|||||||
|
|
||||||
impl TokenResponse {
|
impl TokenResponse {
|
||||||
fn to_oauth_token(self) -> Token {
|
fn to_oauth_token(self) -> Token {
|
||||||
let expires_ts = chrono::UTC::now().timestamp() + self.expires_in.unwrap_or(0);
|
let expires_ts = chrono::Utc::now().timestamp() + self.expires_in.unwrap_or(0);
|
||||||
|
|
||||||
Token {
|
Token {
|
||||||
access_token: self.access_token.unwrap(),
|
access_token: self.access_token.unwrap(),
|
||||||
|
|||||||
10
src/types.rs
10
src/types.rs
@@ -1,4 +1,4 @@
|
|||||||
use chrono::{DateTime, UTC, TimeZone};
|
use chrono::{DateTime, Utc, TimeZone};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
@@ -203,12 +203,12 @@ impl Token {
|
|||||||
if self.access_token.len() == 0 {
|
if self.access_token.len() == 0 {
|
||||||
panic!("called expired() on unset token");
|
panic!("called expired() on unset token");
|
||||||
}
|
}
|
||||||
self.expiry_date() <= UTC::now()
|
self.expiry_date() <= Utc::now()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a DateTime object representing our expiry date.
|
/// Returns a DateTime object representing our expiry date.
|
||||||
pub fn expiry_date(&self) -> DateTime<UTC> {
|
pub fn expiry_date(&self) -> DateTime<Utc> {
|
||||||
UTC.timestamp(self.expires_in_timestamp
|
Utc.timestamp(self.expires_in_timestamp
|
||||||
.expect("Tokens without an absolute expiry are invalid"),
|
.expect("Tokens without an absolute expiry are invalid"),
|
||||||
0)
|
0)
|
||||||
}
|
}
|
||||||
@@ -220,7 +220,7 @@ impl Token {
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.expires_in_timestamp = Some(UTC::now().timestamp() + self.expires_in.unwrap());
|
self.expires_in_timestamp = Some(Utc::now().timestamp() + self.expires_in.unwrap());
|
||||||
self.expires_in = None;
|
self.expires_in = None;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user