-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
244 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod comment; | ||
pub mod oauth; | ||
pub mod pv_counter; | ||
pub mod user; | ||
pub mod pv_counter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Debug, Clone, Deserialize)] | ||
pub struct OAuthQuery { | ||
pub redirect: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
use crate::dto::oauth::OAuthQuery; | ||
use crate::service::auth::AuthService; | ||
use crate::utils::jwt::OptionalClaims; | ||
use spring_web::axum::response::{IntoResponse, Redirect}; | ||
use spring_web::error::Result; | ||
use spring_web::extractor::{Component, Path, RawQuery}; | ||
use spring_web::extractor::{Component, Path, Query, RawQuery}; | ||
use spring_web::get; | ||
|
||
#[get("/api/oauth/:ty/render")] | ||
async fn oauth_render( | ||
Path(ty): Path<String>, | ||
Component(auth): Component<AuthService>, | ||
Query(auth_query): Query<OAuthQuery>, | ||
) -> Result<impl IntoResponse> { | ||
let auth_server = auth.get_auth_server(&ty)?; | ||
let auth_server = auth.get_auth_server(&ty, auth_query)?; | ||
Ok(Redirect::to(&auth_server.authorize().await?)) | ||
} | ||
|
||
#[get("/api/oauth/:ty/callback")] | ||
async fn oauth_callback( | ||
claims: OptionalClaims, | ||
Path(ty): Path<String>, | ||
RawQuery(query): RawQuery, | ||
Query(auth_query): Query<OAuthQuery>, | ||
Component(auth): Component<AuthService>, | ||
) -> Result<impl IntoResponse> { | ||
let auth_server = auth.get_auth_server(&ty)?; | ||
auth_server.login(query.unwrap_or_default()).await?; | ||
Ok("") | ||
let auth_server = auth.get_auth_server(&ty, auth_query)?; | ||
auth_server.login(query.unwrap_or_default(), claims).await | ||
} |
Oops, something went wrong.