Skip to content

Commit

Permalink
user login
Browse files Browse the repository at this point in the history
  • Loading branch information
holmofy committed Nov 3, 2024
1 parent f175c63 commit d1fa13f
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 138 deletions.
7 changes: 4 additions & 3 deletions config/app.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[web]
port = 80
connect_info = true
graceful = true

Expand Down Expand Up @@ -26,8 +27,8 @@ one_indexed = true
uri = "redis://127.0.0.1/"

[raline]
site_url = "http://localhost:8080"
server_url = "http://localhost:8080"
site_url = "http://gwy.dtiku.cn"
server_url = "http://gwy.dtiku.cn"

[logger]
pretty_backtrace = true
Expand All @@ -36,6 +37,6 @@ override_filter = "info,sea_orm=trace"
[auth]
qq = { client_id = "", client_secret = "" }
weibo = { client_id = "", client_secret = "" }
wechat = { client_id = "", client_secret = "" }
wechat = { client_id = "wxdc790efa67d6ab21", client_secret = "0f6f7847a39f6fa3ed248bddcbd50227" }
github = { client_id = "", client_secret = "" }
twitter = { client_id = "", client_secret = "" }
3 changes: 2 additions & 1 deletion src/dto/mod.rs
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;
6 changes: 6 additions & 0 deletions src/dto/oauth.rs
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>,
}
14 changes: 9 additions & 5 deletions src/http/oauth.rs
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
}
Loading

0 comments on commit d1fa13f

Please sign in to comment.