-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Essential work started towards fixing #346
- Loading branch information
1 parent
c121f53
commit 9871c63
Showing
6 changed files
with
215 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,94 @@ | ||
use derive_builder::Builder; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::skip_serializing_none; | ||
|
||
use super::link::OPDSLinkType; | ||
use super::link::OPDSLink; | ||
|
||
pub const OPDS_AUTHENTICATION_DOCUMENT_REL: &str = "http://opds-spec.org/auth/document"; | ||
pub const OPDS_AUTHENTICATION_DOCUMENT_TYPE: &str = | ||
"application/opds-authentication+json"; | ||
|
||
/// A struct for representing an authentication document | ||
/// | ||
/// See https://drafts.opds.io/authentication-for-opds-1.0.html#23-syntax | ||
#[derive(Debug, Serialize, Deserialize)] | ||
#[derive(Debug, Clone, Builder, Serialize, Deserialize)] | ||
#[builder(build_fn(error = "crate::CoreError"), default, setter(into))] | ||
#[skip_serializing_none] | ||
pub struct AuthenticationDocument { | ||
pub struct OPDSAuthenticationDocument { | ||
/// Unique identifier for the Catalog provider and canonical location for the Authentication Document. | ||
/// This is actually a URL | ||
id: String, | ||
/// A list of supported Authentication Flows as defined in section [3. Authentication Flows](https://drafts.opds.io/authentication-for-opds-1.0.html#3-authentication-flows). | ||
authentication: Vec<SupportedAuthFlow>, | ||
authentication: Vec<OPDSAuthenticationFlow>, | ||
/// Title of the Catalog being accessed. | ||
title: String, | ||
/// A description of the service being displayed to the user. | ||
description: Option<String>, | ||
/// A list of links using the same syntax as defined in 2.3.2. Links. | ||
links: Option<Vec<OPDSLink>>, | ||
} | ||
|
||
impl Default for OPDSAuthenticationDocument { | ||
fn default() -> Self { | ||
Self { | ||
id: String::from("/opds/v2.0/auth"), | ||
authentication: vec![OPDSAuthenticationFlow::default()], | ||
title: String::from("Stump OPDS V2 Auth"), | ||
description: None, | ||
links: Some(vec![OPDSLink::help(), OPDSLink::logo()]), | ||
} | ||
} | ||
} | ||
|
||
/// A struct for representing a supported authentication flow | ||
/// | ||
/// See https://drafts.opds.io/authentication-for-opds-1.0.html#3-authentication-flows | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct AuthenticationFlow { | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct OPDSAuthenticationFlow { | ||
/// A URI that identifies the nature of an Authentication Flow. | ||
#[serde(rename = "type")] | ||
_type: SupportedAuthFlow, | ||
/// The URI of the authentication flow | ||
uri: String, | ||
_type: OPDSSupportedAuthFlow, | ||
// /// The URI of the authentication flow | ||
// uri: String, | ||
/// A list of labels that can be used to provide alternate labels for fields that the client will display to the user. | ||
labels: Option<OPDSAuthenticationLabels>, | ||
} | ||
|
||
impl Default for OPDSAuthenticationFlow { | ||
fn default() -> Self { | ||
Self { | ||
_type: OPDSSupportedAuthFlow::Basic, | ||
labels: Some(OPDSAuthenticationLabels { | ||
login: Some(String::from("Username")), | ||
password: Some(String::from("Password")), | ||
}), | ||
} | ||
} | ||
} | ||
|
||
/// A struct for representing authentication labels, meant to provide alternate labels | ||
/// for fields that the client will display to the user. | ||
/// | ||
/// See https://drafts.opds.io/authentication-for-opds-1.0.html#311-labels | ||
#[derive(Debug, Serialize, Deserialize)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
#[skip_serializing_none] | ||
pub struct AuthenticationLabels { | ||
pub struct OPDSAuthenticationLabels { | ||
login: Option<String>, | ||
password: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub enum SupportedAuthFlow { | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub enum OPDSSupportedAuthFlow { | ||
#[serde(rename = "http://opds-spec.org/auth/basic")] | ||
Basic, | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct AuthenticateLink { | ||
/// The URI of the authentication document | ||
href: String, | ||
/// The type of the link | ||
#[serde(rename = "type")] | ||
_type: OPDSLinkType, | ||
} | ||
|
||
impl AuthenticateLink { | ||
pub fn new(href: String) -> Self { | ||
Self { | ||
href, | ||
_type: OPDSLinkType::OpdsAuth, | ||
impl OPDSSupportedAuthFlow { | ||
pub fn description(&self) -> &str { | ||
match self { | ||
OPDSSupportedAuthFlow::Basic => { | ||
"Enter your username and password to authenticate." | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use derive_builder::Builder; | ||
use serde::{Deserialize, Serialize}; | ||
use serde_with::skip_serializing_none; | ||
|
||
use super::link::OPDSLinkType; | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct OPDSDynamicProperties(serde_json::Value); | ||
|
||
#[derive(Debug, Default, Builder, Clone, Serialize, Deserialize)] | ||
#[builder(build_fn(error = "crate::CoreError"), default, setter(into))] | ||
#[skip_serializing_none] | ||
pub struct OPDSProperties { | ||
authenticate: Option<OPDSAuthenticateProperties>, | ||
#[serde(flatten)] | ||
dynamic_properties: Option<OPDSDynamicProperties>, | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub struct OPDSAuthenticateProperties { | ||
/// The URI of the authentication document | ||
href: String, | ||
/// The type of the link | ||
#[serde(rename = "type")] | ||
_type: OPDSLinkType, | ||
} | ||
|
||
impl Default for OPDSAuthenticateProperties { | ||
fn default() -> Self { | ||
Self { | ||
href: String::from("/opds/v2.0/auth"), | ||
_type: OPDSLinkType::OpdsAuth, | ||
} | ||
} | ||
} | ||
|
||
impl OPDSAuthenticateProperties { | ||
pub fn new(href: String) -> Self { | ||
Self { | ||
href, | ||
_type: OPDSLinkType::OpdsAuth, | ||
} | ||
} | ||
} |