client-api: Add auth_type and session accessors to IncomingAuthData

This commit is contained in:
Jonas Platte 2021-08-18 20:33:26 +02:00
parent 7a581038e3
commit 31a0845b66
No known key found for this signature in database
GPG Key ID: CC154DE0E30B7C67
2 changed files with 54 additions and 18 deletions

View File

@ -1,5 +1,9 @@
# [unreleased]
Improvements
* Add `auth_type` and `session` accessors to `uiaa::IncomingAuthData`
# 0.12.1
Improvements:

View File

@ -69,30 +69,62 @@ impl<'a> AuthData<'a> {
/// Returns the value of the `type` field, if it exists.
pub fn auth_type(&self) -> Option<&'a str> {
match self {
AuthData::Password(_) => Some("m.login.password"),
AuthData::ReCaptcha(_) => Some("m.login.recaptcha"),
AuthData::Token(_) => Some("m.login.token"),
AuthData::OAuth2(_) => Some("m.login.oauth2"),
AuthData::EmailIdentity(_) => Some("m.login.email.identity"),
AuthData::Msisdn(_) => Some("m.login.msisdn"),
AuthData::Dummy(_) => Some("m.login.dummy"),
AuthData::FallbackAcknowledgement(_) => None,
AuthData::_Custom(c) => Some(c.auth_type),
Self::Password(_) => Some("m.login.password"),
Self::ReCaptcha(_) => Some("m.login.recaptcha"),
Self::Token(_) => Some("m.login.token"),
Self::OAuth2(_) => Some("m.login.oauth2"),
Self::EmailIdentity(_) => Some("m.login.email.identity"),
Self::Msisdn(_) => Some("m.login.msisdn"),
Self::Dummy(_) => Some("m.login.dummy"),
Self::FallbackAcknowledgement(_) => None,
Self::_Custom(c) => Some(c.auth_type),
}
}
/// Returns the value of the `session` field, if it exists.
pub fn session(&self) -> Option<&'a str> {
match self {
AuthData::Password(x) => x.session,
AuthData::ReCaptcha(x) => x.session,
AuthData::Token(x) => x.session,
AuthData::OAuth2(x) => x.session,
AuthData::EmailIdentity(x) => x.session,
AuthData::Msisdn(x) => x.session,
AuthData::Dummy(x) => x.session,
AuthData::FallbackAcknowledgement(x) => Some(x.session),
AuthData::_Custom(x) => x.session,
Self::Password(x) => x.session,
Self::ReCaptcha(x) => x.session,
Self::Token(x) => x.session,
Self::OAuth2(x) => x.session,
Self::EmailIdentity(x) => x.session,
Self::Msisdn(x) => x.session,
Self::Dummy(x) => x.session,
Self::FallbackAcknowledgement(x) => Some(x.session),
Self::_Custom(x) => x.session,
}
}
}
impl IncomingAuthData {
/// Returns the value of the `type` field, if it exists.
pub fn auth_type(&self) -> Option<&str> {
match self {
Self::Password(_) => Some("m.login.password"),
Self::ReCaptcha(_) => Some("m.login.recaptcha"),
Self::Token(_) => Some("m.login.token"),
Self::OAuth2(_) => Some("m.login.oauth2"),
Self::EmailIdentity(_) => Some("m.login.email.identity"),
Self::Msisdn(_) => Some("m.login.msisdn"),
Self::Dummy(_) => Some("m.login.dummy"),
Self::FallbackAcknowledgement(_) => None,
Self::_Custom(c) => Some(&c.auth_type),
}
}
/// Returns the value of the `session` field, if it exists.
pub fn session(&self) -> Option<&str> {
match self {
Self::Password(x) => x.session.as_deref(),
Self::ReCaptcha(x) => x.session.as_deref(),
Self::Token(x) => x.session.as_deref(),
Self::OAuth2(x) => x.session.as_deref(),
Self::EmailIdentity(x) => x.session.as_deref(),
Self::Msisdn(x) => x.session.as_deref(),
Self::Dummy(x) => x.session.as_deref(),
Self::FallbackAcknowledgement(x) => Some(&x.session),
Self::_Custom(x) => x.session.as_deref(),
}
}
}