This commit is contained in:
18
src/auth.rs
18
src/auth.rs
@@ -1,11 +1,14 @@
|
||||
use axum::{
|
||||
async_trait,
|
||||
extract::{FromRequestParts, FromRef},
|
||||
http::{StatusCode, request::Parts},
|
||||
extract::{FromRef, FromRequestParts},
|
||||
http::{request::Parts, StatusCode},
|
||||
};
|
||||
use serde::Deserialize;
|
||||
|
||||
use crate::{config::OpenIDConfig, error::{ApiError, ApiErrorJson}};
|
||||
use crate::{
|
||||
config::OpenIDConfig,
|
||||
error::{ApiError, ApiErrorJson},
|
||||
};
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct User {
|
||||
@@ -26,8 +29,7 @@ where
|
||||
|
||||
// Create a request to the auth server
|
||||
// TODO: Do some discovery to find the correct url for this instead of assuming
|
||||
let mut req = reqwest::Client::new()
|
||||
.get(format!("{}/userinfo", openid.base_url));
|
||||
let mut req = reqwest::Client::new().get(format!("{}/userinfo", openid.base_url));
|
||||
|
||||
// Add auth header to the request if it exists
|
||||
if let Some(auth) = parts.headers.get(axum::http::header::AUTHORIZATION) {
|
||||
@@ -35,14 +37,16 @@ where
|
||||
}
|
||||
|
||||
// Send the request
|
||||
let res = req.send()
|
||||
let res = req
|
||||
.send()
|
||||
.await
|
||||
.map_err(|err| ApiError::new(StatusCode::INTERNAL_SERVER_ERROR, err.into()))?;
|
||||
|
||||
// If the request is success full the auth token is valid and we are given userinfo
|
||||
let status = res.status();
|
||||
if status.is_success() {
|
||||
let user = res.json()
|
||||
let user = res
|
||||
.json()
|
||||
.await
|
||||
.map_err(|err| ApiError::new(StatusCode::INTERNAL_SERVER_ERROR, err.into()))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user