mirror of
https://github.com/OMGeeky/yup-oauth2.git
synced 2026-01-05 02:40:28 +01:00
fix(json): assure we understand json errors
We would actually fail to decode an error, and then assume it's a valid result, unwrapping another failed attempt to decode the json string returned by the server. Cause seems to be that the json error structure now conains an additional field, 'error_uri'. * we removed a debug printing ... . * incremented version
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
[package]
|
||||
|
||||
name = "yup-oauth2"
|
||||
version = "0.4.1"
|
||||
version = "0.4.2"
|
||||
authors = ["Sebastian Thiel <byronimo@gmail.com>"]
|
||||
repository = "https://github.com/Byron/yup-oauth2"
|
||||
description = "A partial oauth2 implementation, providing the 'device' authorization flow"
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
],
|
||||
},
|
||||
],
|
||||
"SublimeLinter":
|
||||
"SublimeLinter":
|
||||
{
|
||||
"linters":
|
||||
{
|
||||
"rust": {
|
||||
"@disable": false,
|
||||
"@disable": true,
|
||||
"args": [],
|
||||
"crate-root": null,
|
||||
"excludes": [],
|
||||
|
||||
@@ -10,8 +10,9 @@ pub trait Flow {
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct JsonError {
|
||||
pub error: String,
|
||||
pub error: Option<String>,
|
||||
pub error_description: Option<String>,
|
||||
pub error_uri: Option<String>,
|
||||
}
|
||||
|
||||
/// Represents all implemented token types
|
||||
|
||||
@@ -84,12 +84,13 @@ pub enum RequestError {
|
||||
|
||||
impl From<JsonError> 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<C> DeviceFlow<C>
|
||||
match json::from_str::<JsonError>(&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;
|
||||
|
||||
@@ -98,8 +98,10 @@ impl<C> RefreshFlow<C>
|
||||
match json::from_str::<JsonError>(&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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user