Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Add temporary UIAuth provider #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/api/r0/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,60 @@ impl Handler for Login {
}
}

/// Temporary UIAuth provider.
pub struct LoginFlows;

#[derive(Debug, Serialize)]
struct Flows {
pub flows: Vec<LoginType>
}

#[derive(Debug, Serialize)]
struct LoginType {
#[serde(rename="type")]
pub login_type: String
}

impl MiddlewareChain for LoginFlows {
fn chain() -> Chain {
Chain::new(LoginFlows)
}
}

impl Handler for LoginFlows {
fn handle(&self, _: &mut Request) -> IronResult<Response> {
let pass_login = LoginType { login_type: "m.login.password".to_string() };
let response = Flows { flows: vec![pass_login] };

Ok(Response::with((status::Ok, SerializableResponse(response))))
}
}


#[cfg(test)]
mod tests {
use test::Test;

#[test]
fn get_available_flows() {
let test = Test::new();

let response = test.get("/_matrix/client/r0/login");
let flows = response.json().find("flows");

assert!(flows.is_some());
assert_eq!(flows.unwrap().as_array().unwrap().len(), 1);

let login_type = flows.unwrap()
.as_array().unwrap()
.get(0).unwrap()
.as_object().unwrap()
.get("type").unwrap()
.as_str().unwrap();

assert_eq!(login_type, "m.login.password");
}

#[test]
fn valid_credentials() {
let test = Test::new();
Expand Down
2 changes: 1 addition & 1 deletion src/api/r0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use self::account::{
pub use self::directory::{GetRoomAlias, DeleteRoomAlias, PutRoomAlias};
pub use self::event_creation::{SendMessageEvent, StateMessageEvent};
pub use self::join::{InviteToRoom, JoinRoom, JoinRoomWithIdOrAlias};
pub use self::login::Login;
pub use self::login::{Login, LoginFlows};
pub use self::logout::Logout;
pub use self::members::Members;
pub use self::profile::{Profile, GetAvatarUrl, PutAvatarUrl, GetDisplayName, PutDisplayName};
Expand Down
2 changes: 2 additions & 0 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use api::r0::{
GetRoomAlias,
GetFilter,
GetTags,
LoginFlows,
InviteToRoom,
JoinRoom,
JoinRoomWithIdOrAlias,
Expand Down Expand Up @@ -79,6 +80,7 @@ impl<'a> Server<'a> {
"delete_room_alias",
);
r0_router.put("/directory/room/:room_alias", PutRoomAlias::chain(), "put_room_alias");
r0_router.get("/login", LoginFlows::chain(), "login_flows");
r0_router.post("/login", Login::chain(), "login");
r0_router.post("/logout", Logout::chain(), "logout");
r0_router.post("/register", Register::chain(), "register");
Expand Down