1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-11-20 12:02:22 +03:00

Add a GraphQL mutation to create arbitrary OAuth2 sessions.

This commit is contained in:
Quentin Gliech
2023-09-08 19:28:46 +02:00
parent b8012bb66c
commit 83ca90ee3d
8 changed files with 369 additions and 71 deletions

View File

@@ -510,6 +510,7 @@ async fn test_oauth2_client_credentials(pool: PgPool) {
mutation {
addUser(input: {username: "alice"}) {
user {
id
username
}
}
@@ -519,15 +520,42 @@ async fn test_oauth2_client_credentials(pool: PgPool) {
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let response: GraphQLResponse = response.json();
assert!(response.errors.is_empty());
assert!(response.errors.is_empty(), "{:?}", response.errors);
let user_id = &response.data["addUser"]["user"]["id"];
assert_eq!(
response.data,
serde_json::json!({
"addUser": {
"user": {
"id": user_id,
"username": "alice"
}
}
})
);
// We should now be able to create an arbitrary access token for the user
let request = Request::post("/graphql")
.bearer(&access_token)
.json(serde_json::json!({
"query": r#"
mutation CreateSession($userId: String!, $scope: String!) {
createOauth2Session(input: {userId: $userId, permanent: true, scope: $scope}) {
accessToken
refreshToken
}
}
"#,
"variables": {
"userId": user_id,
"scope": "urn:matrix:org.matrix.msc2967.client:device:AABBCCDDEE urn:matrix:org.matrix.msc2967.client:api:* urn:synapse:admin:*"
},
}));
let response = state.request(request).await;
response.assert_status(StatusCode::OK);
let response: GraphQLResponse = response.json();
assert!(response.errors.is_empty(), "{:?}", response.errors);
assert!(response.data["createOauth2Session"]["refreshToken"].is_null());
assert!(response.data["createOauth2Session"]["accessToken"].is_string());
}