Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/query/service/src/servers/http/v1/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use databend_common_users::UserApiProvider;
use jwt_simple::prelude::Serialize;
use poem::error::Result as PoemResult;
use poem::web::Json;
Expand All @@ -24,6 +25,9 @@ use crate::servers::http::v1::HttpQueryContext;
pub struct VerifyResponse {
tenant: String,
user: String,
auth_type: String,
is_configured: bool,
default_role: String,
roles: Vec<String>,
}

Expand All @@ -35,14 +39,25 @@ pub async fn verify_handler(ctx: &HttpQueryContext) -> PoemResult<impl IntoRespo
.session
.get_current_user()
.map_err(HttpErrorCode::server_error)?;
let is_configured = UserApiProvider::instance()
.get_configured_user(&user.name)
.is_some();
let auth_type = user.auth_info.get_type().to_str().to_string();
let default_role = user.option.default_role().cloned().unwrap_or_default();
let roles = ctx
.session
.get_all_effective_roles()
.await
.map_err(HttpErrorCode::server_error)?;
.map_err(HttpErrorCode::server_error)?
.into_iter()
.map(|r| r.name)
.collect();
Ok(Json(VerifyResponse {
tenant: tenant.tenant_name().to_string(),
user: user.name,
roles: roles.into_iter().map(|r| r.name).collect(),
is_configured,
auth_type,
default_role,
roles,
}))
}