add AuthScheme AccessTokenOptional in ruma_wrapper
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
5a15dab7a9
commit
4dfd5a7c15
1 changed files with 25 additions and 4 deletions
|
@ -83,7 +83,7 @@ where
|
|||
appservice_registration
|
||||
{
|
||||
match metadata.authentication {
|
||||
AuthScheme::AccessToken => {
|
||||
AuthScheme::AccessToken | AuthScheme::AccessTokenOptional => {
|
||||
let user_id = query_params.user_id.map_or_else(
|
||||
|| {
|
||||
UserId::parse_with_server_name(
|
||||
|
@ -95,7 +95,7 @@ where
|
|||
|s| UserId::parse(s).unwrap(),
|
||||
);
|
||||
|
||||
if !services().users.exists(&user_id).unwrap() {
|
||||
if !services().users.exists(&user_id)? {
|
||||
return Err(Error::BadRequest(ErrorKind::Forbidden, "User does not exist."));
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ where
|
|||
_ => return Err(Error::BadRequest(ErrorKind::MissingToken, "Missing access token.")),
|
||||
};
|
||||
|
||||
match services().users.find_from_token(token).unwrap() {
|
||||
match services().users.find_from_token(token)? {
|
||||
None => {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::UnknownToken {
|
||||
|
@ -127,6 +127,27 @@ where
|
|||
},
|
||||
}
|
||||
},
|
||||
AuthScheme::AccessTokenOptional => {
|
||||
let token = token.unwrap_or("");
|
||||
|
||||
if token.is_empty() {
|
||||
(None, None, None, false)
|
||||
} else {
|
||||
match services().users.find_from_token(token)? {
|
||||
None => {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::UnknownToken {
|
||||
soft_logout: false,
|
||||
},
|
||||
"Unknown access token.",
|
||||
))
|
||||
},
|
||||
Some((user_id, device_id)) => {
|
||||
(Some(user_id), Some(OwnedDeviceId::from(device_id)), None, false)
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
AuthScheme::ServerSignatures => {
|
||||
let TypedHeader(Authorization(x_matrix)) =
|
||||
parts.extract::<TypedHeader<Authorization<XMatrix>>>().await.map_err(|e| {
|
||||
|
@ -219,7 +240,7 @@ where
|
|||
_ => return Err(Error::BadRequest(ErrorKind::MissingToken, "Missing access token.")),
|
||||
};
|
||||
|
||||
match services().users.find_from_token(token).unwrap() {
|
||||
match services().users.find_from_token(token)? {
|
||||
None => {
|
||||
return Err(Error::BadRequest(
|
||||
ErrorKind::UnknownToken {
|
||||
|
|
Loading…
Add table
Reference in a new issue