From 5bfc7cfde35280eebb086459000d96c324500763 Mon Sep 17 00:00:00 2001 From: BlackDex Date: Mon, 14 Nov 2022 17:22:37 +0100 Subject: [PATCH] Added missing `register` endpoint to `identity` In the upcomming web-vault and other clients they changed the register endpoint from `/api/accounts/register` to `/identity/register`. This PR adds the new endpoint to already be compatible with the new clients. Fixes #2889 --- src/api/core/accounts.rs | 8 ++++++-- src/api/identity.rs | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/api/core/accounts.rs b/src/api/core/accounts.rs index 03be4c41..2cd500d1 100644 --- a/src/api/core/accounts.rs +++ b/src/api/core/accounts.rs @@ -42,7 +42,7 @@ pub fn routes() -> Vec { #[derive(Deserialize, Debug)] #[allow(non_snake_case)] -struct RegisterData { +pub struct RegisterData { Email: String, Kdf: Option, KdfIterations: Option, @@ -82,7 +82,11 @@ fn enforce_password_hint_setting(password_hint: &Option) -> EmptyResult } #[post("/accounts/register", data = "")] -async fn register(data: JsonUpcase, mut conn: DbConn) -> JsonResult { +async fn register(data: JsonUpcase, conn: DbConn) -> JsonResult { + _register(data, conn).await +} + +pub async fn _register(data: JsonUpcase, mut conn: DbConn) -> JsonResult { let data: RegisterData = data.into_inner().data; let email = data.Email.to_lowercase(); diff --git a/src/api/identity.rs b/src/api/identity.rs index a509df87..9e747c7d 100644 --- a/src/api/identity.rs +++ b/src/api/identity.rs @@ -9,7 +9,7 @@ use serde_json::Value; use crate::{ api::{ - core::accounts::{PreloginData, _prelogin}, + core::accounts::{PreloginData, RegisterData, _prelogin, _register}, core::two_factor::{duo, email, email::EmailTokenData, yubikey}, ApiResult, EmptyResult, JsonResult, JsonUpcase, }, @@ -20,7 +20,7 @@ use crate::{ }; pub fn routes() -> Vec { - routes![login, prelogin] + routes![login, prelogin, identity_register] } #[post("/connect/token", data = "")] @@ -434,6 +434,11 @@ async fn prelogin(data: JsonUpcase, conn: DbConn) -> Json { _prelogin(data, conn).await } +#[post("/accounts/register", data = "")] +async fn identity_register(data: JsonUpcase, conn: DbConn) -> JsonResult { + _register(data, conn).await +} + // https://github.com/bitwarden/jslib/blob/master/common/src/models/request/tokenRequest.ts // https://github.com/bitwarden/mobile/blob/master/src/Core/Models/Request/TokenRequest.cs #[derive(Debug, Clone, Default, FromForm)]