-
-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
724538b
commit 4855ba1
Showing
15 changed files
with
157 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,19 @@ | ||
use axum::{ | ||
http::StatusCode, | ||
response::{IntoResponse, Response}, | ||
}; | ||
use shield::ShieldError; | ||
|
||
pub struct RouteError(ShieldError); | ||
|
||
impl IntoResponse for RouteError { | ||
fn into_response(self) -> Response { | ||
(StatusCode::INTERNAL_SERVER_ERROR, self.0.to_string()).into_response() | ||
} | ||
} | ||
|
||
impl From<ShieldError> for RouteError { | ||
fn from(value: ShieldError) -> Self { | ||
Self(value) | ||
} | ||
} |
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,5 +1,11 @@ | ||
mod error; | ||
mod extract; | ||
mod path; | ||
mod response; | ||
mod router; | ||
mod routes; | ||
|
||
pub use shield_tower::*; | ||
|
||
pub use extract::*; | ||
pub use router::*; |
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,7 @@ | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize)] | ||
pub struct AuthPath { | ||
pub provider_id: String, | ||
pub subprovider_id: 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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use axum::response::{IntoResponse, Redirect, Response}; | ||
|
||
pub struct RouteResponse(shield::Response); | ||
|
||
impl IntoResponse for RouteResponse { | ||
fn into_response(self) -> Response { | ||
match self.0 { | ||
shield::Response::Redirect(url) => Redirect::to(&url).into_response(), | ||
} | ||
} | ||
} | ||
|
||
impl From<shield::Response> for RouteResponse { | ||
fn from(value: shield::Response) -> Self { | ||
Self(value) | ||
} | ||
} |
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,18 @@ | ||
use axum::{ | ||
routing::{get, post}, | ||
Router, | ||
}; | ||
|
||
use crate::routes::{sign_in, sign_in_callback, sign_out}; | ||
|
||
pub fn auth_router<S: Clone + Send + Sync + 'static>() -> Router<S> { | ||
Router::new() | ||
.route("/sign-in/:provider_id", post(sign_in)) | ||
.route("/sign-in/:provider_id/:subprovider_id", post(sign_in)) | ||
.route("/sign-in/callback/:provider_id", get(sign_in_callback)) | ||
.route( | ||
"/sign-in/callback/:provider_id/:subprovider_id", | ||
get(sign_in_callback), | ||
) | ||
.route("/sign-out", post(sign_out)) | ||
} |
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,7 @@ | ||
mod sign_in; | ||
mod sign_in_callback; | ||
mod sign_out; | ||
|
||
pub use sign_in::*; | ||
pub use sign_in_callback::*; | ||
pub use sign_out::*; |
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,32 @@ | ||
use axum::extract::Path; | ||
use shield::SignInRequest; | ||
|
||
use crate::{ | ||
error::RouteError, | ||
extract::{ExtractSession, ExtractShield}, | ||
path::AuthPath, | ||
response::RouteResponse, | ||
}; | ||
|
||
pub async fn sign_in( | ||
Path(AuthPath { | ||
provider_id, | ||
subprovider_id, | ||
}): Path<AuthPath>, | ||
ExtractShield(shield): ExtractShield, | ||
ExtractSession(session): ExtractSession, | ||
) -> Result<RouteResponse, RouteError> { | ||
let response = shield | ||
.sign_in( | ||
SignInRequest { | ||
provider_id, | ||
subprovider_id, | ||
data: None, | ||
form_data: None, | ||
}, | ||
session, | ||
) | ||
.await?; | ||
|
||
Ok(response.into()) | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/integrations/shield-axum/src/routes/sign_in_callback.rs
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,34 @@ | ||
use axum::extract::{Path, Query}; | ||
use serde_json::Value; | ||
use shield::SignInCallbackRequest; | ||
|
||
use crate::{ | ||
error::RouteError, | ||
extract::{ExtractSession, ExtractShield}, | ||
path::AuthPath, | ||
response::RouteResponse, | ||
}; | ||
|
||
pub async fn sign_in_callback( | ||
Path(AuthPath { | ||
provider_id, | ||
subprovider_id, | ||
}): Path<AuthPath>, | ||
Query(query): Query<Value>, | ||
ExtractShield(shield): ExtractShield, | ||
ExtractSession(session): ExtractSession, | ||
) -> Result<RouteResponse, RouteError> { | ||
let response = shield | ||
.sign_in_callback( | ||
SignInCallbackRequest { | ||
provider_id, | ||
subprovider_id, | ||
query: Some(query), | ||
data: None, | ||
}, | ||
session, | ||
) | ||
.await?; | ||
|
||
Ok(response.into()) | ||
} |
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 @@ | ||
pub async fn sign_out() {} |
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