Skip to content

Commit

Permalink
Merge pull request #74 from go-bazzinga/login-system-workflow-change
Browse files Browse the repository at this point in the history
changed config structure
  • Loading branch information
rosarp-gobazzinga authored Mar 18, 2024
2 parents 26e33bd + 7f75c66 commit 13071bb
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ jobs:
flyctl secrets set --stage AUTH_SIGN_KEY="$AUTH_SIGN_KEY"
flyctl secrets set --stage CLOUDFLARE_API_TOKEN="$CLOUDFLARE_API_TOKEN"
flyctl secrets set --stage GOOGLE_CLIENT_SECRET="$GOOGLE_CLIENT_SECRET"
flyctl deploy --remote-only --build-arg CLOUDFLARE_ACCOUNT_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_ACCOUNT_ID }} --build-arg CLOUDFLARE_NAMESPACE_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_NAMESPACE_ID }} --build-arg GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_SIGNING_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID }}
flyctl deploy --local-only --build-arg CLOUDFLARE_ACCOUNT_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_ACCOUNT_ID }} --build-arg CLOUDFLARE_NAMESPACE_IDENTIFIER=${{ secrets.CLOUDFLARE_WORKERS_KV_NAMESPACE_ID }} --build-arg GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_SIGNING_OAUTH_CLIENT_CREDENTIAL_CLIENT_ID }}
20 changes: 8 additions & 12 deletions AppConfig.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
[auth]
ic_url = "https://ic0.app"
sign_key = ""
auth_ic_url = "https://ic0.app"
auth_sign_key = ""
auth_domain = "https://hot-or-not-auth.fly.dev"
app_domain = "https://hot-or-not-web-leptos-ssr.fly.dev"

[cloudflare]
account_identifier = ""
api_token = ""
namespace_identifier = ""
cloudflare_account_identifier = ""
cloudflare_api_token = ""
cloudflare_namespace_identifier = ""

[[oauth]]
provider_name = "google"
auth_landing_url = "https://hot-or-not-auth.fly.dev/google_oauth2_response"
client_id = ""
client_secret = ""
google_auth_landing_url = "https://hot-or-not-auth.fly.dev/google_oauth2_response"
google_client_id = ""
google_client_secret = ""
54 changes: 19 additions & 35 deletions src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,35 @@ pub fn configure() -> AppConfig {
.merge(Env::raw())
.extract()
.unwrap();
info!("sign: {}", config.auth.sign_key.len());
info!("ctoken: {}", config.cloudflare.api_token.len());
info!(
"gtoken: {}",
config.oauth.get(0).unwrap().client_secret.len()
);
info!("sign: {}", config.auth_sign_key.len());
info!("ctoken: {}", config.cloudflare_api_token.len());
info!("gtoken: {}", config.google_client_secret.len());
config
}

#[cfg(feature = "ssr")]
pub fn cloudflare_config(config: &AppConfig) -> cloudflare_api::connect::ApiClientConfig {
use cloudflare_api::connect::{ApiClientConfig, Credentials, HttpApiClient};
ApiClientConfig {
account_identifier: config.cloudflare.account_identifier.clone(),
namespace_identifier: config.cloudflare.namespace_identifier.clone(),
account_identifier: config.cloudflare_account_identifier.clone(),
namespace_identifier: config.cloudflare_namespace_identifier.clone(),
cloudflare_client: HttpApiClient::new(&Credentials::UserAuthToken {
token: config.cloudflare.api_token.clone(),
token: config.cloudflare_api_token.clone(),
}),
}
}

#[cfg(feature = "ssr")]
pub fn oauth2_client_init(config: &AppConfig) -> oauth2::basic::BasicClient {
let google = config.oauth.get(0).unwrap();
oauth2::basic::BasicClient::new(
oauth2::ClientId::new(google.client_id.to_owned()),
Some(oauth2::ClientSecret::new(google.client_secret.to_owned())),
oauth2::ClientId::new(config.google_client_id.to_owned()),
Some(oauth2::ClientSecret::new(
config.google_client_secret.to_owned(),
)),
oauth2::AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap(),
Some(oauth2::TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap()),
)
.set_redirect_uri(oauth2::RedirectUrl::new(google.auth_landing_url.to_owned()).unwrap())
.set_redirect_uri(oauth2::RedirectUrl::new(config.google_auth_landing_url.to_owned()).unwrap())
}

#[cfg(feature = "ssr")]
Expand Down Expand Up @@ -90,30 +88,16 @@ pub fn cors_layer() -> CorsLayer {

#[derive(Debug, Deserialize, Clone)]
pub struct AppConfig {
pub auth: AuthConfig,
pub cloudflare: CloudflareConfig,
pub oauth: Vec<OAuthConfig>,
}

#[derive(Debug, Deserialize, Clone)]
pub struct AuthConfig {
pub ic_url: String,
pub sign_key: String,
pub auth_ic_url: String,
pub auth_sign_key: String,
pub auth_domain: String,
pub app_domain: String,
}

#[derive(Debug, Deserialize, Clone)]
pub struct CloudflareConfig {
pub account_identifier: String,
pub api_token: String,
pub namespace_identifier: String,
}
pub cloudflare_account_identifier: String,
pub cloudflare_api_token: String,
pub cloudflare_namespace_identifier: String,

#[derive(Debug, Deserialize, Clone)]
pub struct OAuthConfig {
pub provider_name: String,
pub auth_landing_url: String,
pub client_id: String,
pub client_secret: String,
pub google_auth_landing_url: String,
pub google_client_id: String,
pub google_client_secret: String,
}
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ async fn main() {

let app_state = identity::AppState {
leptos_options,
key: Key::from(app_config.auth.sign_key.as_bytes()),
key: Key::from(app_config.auth_sign_key.as_bytes()),
routes: routes.clone(),
oauth2_client,
reqwest_client: reqwest::Client::new(),
auth_domain: Url::parse(&app_config.auth.auth_domain).unwrap(),
app_domain: Url::parse(&app_config.auth.app_domain).unwrap(),
auth_domain: Url::parse(&app_config.auth_domain).unwrap(),
app_domain: Url::parse(&app_config.app_domain).unwrap(),
cloudflare_config,
};
let app_state: identity::AppState = app_state;
Expand Down

0 comments on commit 13071bb

Please sign in to comment.