identity-service-api: Add msisdn validation endpoints
This commit is contained in:
parent
325f2f918c
commit
d53f2ba71b
@ -1,3 +1,4 @@
|
||||
//! Endpoints to create associations with a Matrix ID on the identity server.
|
||||
|
||||
pub mod email;
|
||||
pub mod msisdn;
|
||||
|
5
ruma-identity-service-api/src/association/msisdn.rs
Normal file
5
ruma-identity-service-api/src/association/msisdn.rs
Normal file
@ -0,0 +1,5 @@
|
||||
//! Endpoints to create association between a phone number and a Matrix ID on the identity server.
|
||||
|
||||
pub mod create_msisdn_validation_session;
|
||||
pub mod validate_msisdn;
|
||||
pub mod validate_msisdn_by_phone_number;
|
@ -0,0 +1,3 @@
|
||||
//! Create a session for validation of a phone number.
|
||||
|
||||
pub mod v2;
|
@ -0,0 +1,63 @@
|
||||
//! [POST /_matrix/identity/v2/validate/msisdn/requestToken](https://matrix.org/docs/spec/identity_service/r0.3.0#post-matrix-identity-v2-validate-msisdn-requesttoken)
|
||||
|
||||
use js_int::UInt;
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Creates a session for validating a phone number.",
|
||||
method: POST,
|
||||
name: "create_msisdn_validation_session",
|
||||
path: "/_matrix/identity/v2/validate/msisdn/requestToken",
|
||||
authentication: AccessToken,
|
||||
rate_limited: false,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// A unique string generated by the client, and used to identify the validation attempt.
|
||||
pub client_secret: &'a str,
|
||||
|
||||
/// The two-letter uppercase ISO-3166-1 alpha-2 country code that the number in
|
||||
/// `phone_number` should be parsed as if it were dialled from.
|
||||
pub country: &'a str,
|
||||
|
||||
/// The phone number to validate.
|
||||
pub phone_number: &'a str,
|
||||
|
||||
/// The server will only send an SMS if the send_attempt is a number greater than the most
|
||||
/// recent one which it has seen, scoped to that `country` + `phone_number` +
|
||||
/// `client_secret` triple.
|
||||
pub send_attempt: UInt,
|
||||
|
||||
/// When the validation is completed, the identity server will redirect the user to this
|
||||
/// URL.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub next_link: Option<&'a str>,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// The session ID. Session IDs are opaque strings generated by the identity server.
|
||||
pub sid: String,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Create a new `Request` with the given client secret, country code, phone number, the
|
||||
/// `send_attempt` number and the next link to go to after validation.
|
||||
pub fn new(
|
||||
client_secret: &'a str,
|
||||
country: &'a str,
|
||||
phone_number: &'a str,
|
||||
send_attempt: js_int::UInt,
|
||||
next_link: Option<&'a str>,
|
||||
) -> Self {
|
||||
Self { client_secret, country, phone_number, send_attempt, next_link }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Create a new `Response` with the given session ID.
|
||||
pub fn new(sid: String) -> Self {
|
||||
Self { sid }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
//! Validate the ownership of a phone number.
|
||||
|
||||
pub mod v2;
|
@ -0,0 +1,44 @@
|
||||
//! [POST /_matrix/identity/v2/validate/msisdn/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#post-matrix-identity-v2-validate-msisdn-submittoken)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Validate ownership of an phone number.",
|
||||
method: POST,
|
||||
name: "validate_msisdn",
|
||||
path: "/_matrix/identity/v2/validate/msisdn/submitToken",
|
||||
authentication: AccessToken,
|
||||
rate_limited: false,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The session ID, generated by the `requestToken` call.
|
||||
pub sid: &'a str,
|
||||
|
||||
/// The client secret that was supplied to the `requestToken` call.
|
||||
pub client_secret: &'a str,
|
||||
|
||||
/// The token generated by the `requestToken` call and sent to the user.
|
||||
pub token: &'a str,
|
||||
}
|
||||
|
||||
response: {
|
||||
/// Whether the validation was successful or not.
|
||||
pub success: bool,
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Create a new `Request` with the given session ID, client secret and token.
|
||||
pub fn new(sid: &'a str, client_secret: &'a str, token: &'a str) -> Self {
|
||||
Self { sid, client_secret, token }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Create a new `Response` with the success status.
|
||||
pub fn new(success: bool) -> Self {
|
||||
Self { success }
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
//! Endpoint to validate the ownership of a phone number by the end user.
|
||||
|
||||
pub mod v2;
|
@ -0,0 +1,45 @@
|
||||
//! [GET /_matrix/identity/v2/validate/msisdn/submitToken](https://matrix.org/docs/spec/identity_service/r0.3.0#get-matrix-identity-v2-validate-msisdn-submittoken)
|
||||
|
||||
use ruma_api::ruma_api;
|
||||
|
||||
ruma_api! {
|
||||
metadata: {
|
||||
description: "Validate ownership of an email address.",
|
||||
method: GET,
|
||||
name: "validate_email_by_end_user",
|
||||
path: "/_matrix/identity/v2/validate/msisdn/submitToken",
|
||||
authentication: AccessToken,
|
||||
rate_limited: false,
|
||||
}
|
||||
|
||||
request: {
|
||||
/// The session ID, generated by the `requestToken` call.
|
||||
#[ruma_api(query)]
|
||||
pub sid: &'a str,
|
||||
|
||||
/// The client secret that was supplied to the `requestToken` call.
|
||||
#[ruma_api(query)]
|
||||
pub client_secret: &'a str,
|
||||
|
||||
/// The token generated by the `requestToken` call and sent to the user.
|
||||
#[ruma_api(query)]
|
||||
pub token: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
response: {}
|
||||
}
|
||||
|
||||
impl<'a> Request<'a> {
|
||||
/// Create a new `Request` with the given session ID, client secret and token.
|
||||
pub fn new(sid: &'a str, client_secret: &'a str, token: &'a str) -> Self {
|
||||
Self { sid, client_secret, token }
|
||||
}
|
||||
}
|
||||
|
||||
impl Response {
|
||||
/// Create a new empty `Response`.
|
||||
pub fn new() -> Self {
|
||||
Self {}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user