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

Commit

Permalink
graphql: Fix the createOauth2Session mutation not persisting the chan…
Browse files Browse the repository at this point in the history
…ges to the database
  • Loading branch information
sandhose committed Sep 12, 2023
1 parent 9c97a0c commit 789040d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/graphql/src/mutations/oauth2_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ impl OAuth2SessionMutations {
Some(refresh_token)
};

repo.save().await?;

Ok(CreateOAuth2SessionPayload {
session,
access_token: access_token.access_token,
Expand Down
18 changes: 17 additions & 1 deletion crates/handlers/src/graphql/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ use axum::http::Request;
use hyper::StatusCode;
use mas_data_model::{AccessToken, Client, TokenType, User};
use mas_router::SimpleRoute;
use mas_storage::{oauth2::OAuth2ClientRepository, RepositoryAccess};
use mas_storage::{
oauth2::{OAuth2AccessTokenRepository, OAuth2ClientRepository},
RepositoryAccess,
};
use oauth2_types::{
registration::ClientRegistrationResponse,
requests::AccessTokenResponse,
Expand Down Expand Up @@ -551,4 +554,17 @@ async fn test_oauth2_client_credentials(pool: PgPool) {
assert!(response.errors.is_empty(), "{:?}", response.errors);
assert!(response.data["createOauth2Session"]["refreshToken"].is_null());
assert!(response.data["createOauth2Session"]["accessToken"].is_string());

let token = response.data["createOauth2Session"]["accessToken"]
.as_str()
.unwrap();

// We should find this token in the database
let mut repo = state.repository().await.unwrap();
let token = repo
.oauth2_access_token()
.find_by_token(token)
.await
.unwrap();
assert!(token.is_some());
}

0 comments on commit 789040d

Please sign in to comment.