diff --git a/Cargo.toml b/Cargo.toml index 4d3a22ca0..78b4a6f13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yup-oauth2" -version = "0.4.1" +version = "0.4.2" authors = ["Sebastian Thiel "] repository = "https://github.com/Byron/yup-oauth2" description = "A partial oauth2 implementation, providing the 'device' authorization flow" diff --git a/etc/sublime-text/yup-oauth2-rs.sublime-project b/etc/sublime-text/yup-oauth2-rs.sublime-project index 4a486285c..3489b2700 100644 --- a/etc/sublime-text/yup-oauth2-rs.sublime-project +++ b/etc/sublime-text/yup-oauth2-rs.sublime-project @@ -13,12 +13,12 @@ ], }, ], - "SublimeLinter": + "SublimeLinter": { "linters": { "rust": { - "@disable": false, + "@disable": true, "args": [], "crate-root": null, "excludes": [], diff --git a/src/common.rs b/src/common.rs index f3f21be9b..cd7cbd3ee 100644 --- a/src/common.rs +++ b/src/common.rs @@ -10,8 +10,9 @@ pub trait Flow { #[derive(Deserialize)] pub struct JsonError { - pub error: String, + pub error: Option, pub error_description: Option, + pub error_uri: Option, } /// Represents all implemented token types diff --git a/src/device.rs b/src/device.rs index 5fb99c66d..61012cf3d 100644 --- a/src/device.rs +++ b/src/device.rs @@ -84,12 +84,13 @@ pub enum RequestError { impl From for RequestError { fn from(value: JsonError) -> RequestError { - match &*value.error { + let err_str = value.error.unwrap(); + match &*err_str { "invalid_client" => RequestError::InvalidClient, "invalid_scope" => RequestError::InvalidScope( value.error_description.unwrap_or("no description provided".to_string()) ), - _ => RequestError::NegativeServerResponse(value.error, value.error_description), + _ => RequestError::NegativeServerResponse(err_str, value.error_description), } } } @@ -218,11 +219,12 @@ impl DeviceFlow match json::from_str::(&json_str) { Err(_) => {}, // ignore, move on Ok(res) => { - return Err(RequestError::from(res)) + if res.error.is_some() { + return Err(RequestError::from(res)) + } } } - println!("{:?}", json_str); let decoded: JsonData = json::from_str(&json_str).unwrap(); self.device_code = decoded.device_code; diff --git a/src/refresh.rs b/src/refresh.rs index aed0837bb..6da144867 100644 --- a/src/refresh.rs +++ b/src/refresh.rs @@ -98,8 +98,10 @@ impl RefreshFlow match json::from_str::(&json_str) { Err(_) => {}, Ok(res) => { - self.result = RefreshResult::RefreshError(res.error, res.error_description); - return &self.result; + if let Some(err) = res.error { + self.result = RefreshResult::RefreshError(err, res.error_description); + return &self.result; + } } }