Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
DATABASE_URL=sqlite:db/mines.db
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
REDDIT_CLIENT_ID=
REDDIT_CLIENT_SECRET=
GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=
REDIRECT_HOST=http://localhost:3000 # 8080 for built docker version
6 changes: 0 additions & 6 deletions web-auth/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ pub fn oauth_client(target: OAuthTarget) -> Result<SpecialClient> {
"https://accounts.google.com/o/oauth2/v2/auth",
"https://oauth2.googleapis.com/token",
),
OAuthTarget::Reddit => (
"REDDIT_CLIENT_ID",
"REDDIT_CLIENT_SECRET",
"https://www.reddit.com/api/v1/authorize",
"https://www.reddit.com/api/v1/access_token",
),
OAuthTarget::Github => (
"GITHUB_CLIENT_ID",
"GITHUB_CLIENT_SECRET",
Expand Down
1 change: 0 additions & 1 deletion web-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub use users::{AuthSession, Backend};
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum OAuthTarget {
Google,
Reddit,
Github,
}

Expand Down
47 changes: 1 addition & 46 deletions web-auth/src/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ struct GoogleUserInfo {
email: String,
}

#[derive(Debug, Deserialize)]
struct RedditUserInfo {
name: String,
}

#[derive(Debug, Deserialize)]
struct GithubUserInfo {
login: String,
Expand All @@ -54,22 +49,15 @@ pub enum BackendError {
pub struct Backend {
db: SqlitePool,
google_client: SpecialClient,
reddit_client: SpecialClient,
github_client: SpecialClient,
http_client: reqwest::Client,
}

impl Backend {
pub fn new(
db: SqlitePool,
google_client: SpecialClient,
reddit_client: SpecialClient,
github_client: SpecialClient,
) -> Self {
pub fn new(db: SqlitePool, google_client: SpecialClient, github_client: SpecialClient) -> Self {
Self {
db,
google_client,
reddit_client,
github_client,
http_client: ClientBuilder::new()
.redirect(reqwest::redirect::Policy::none())
Expand All @@ -81,7 +69,6 @@ impl Backend {
pub fn get_client(&self, target: OAuthTarget) -> &SpecialClient {
match target {
OAuthTarget::Google => &self.google_client,
OAuthTarget::Reddit => &self.reddit_client,
OAuthTarget::Github => &self.github_client,
}
}
Expand All @@ -98,12 +85,6 @@ impl Backend {
"https://www.googleapis.com/auth/userinfo.email".to_string(),
))
.url(),
OAuthTarget::Reddit => self
.reddit_client
.authorize_url(CsrfToken::new_random)
.add_extra_param("duration", "permanent")
.add_scope(Scope::new("identity".to_string()))
.url(),
OAuthTarget::Github => self
.github_client
.authorize_url(CsrfToken::new_random)
Expand Down Expand Up @@ -166,32 +147,6 @@ impl AuthnBackend for Backend {
.map_err(Self::Error::Reqwest)?;
(token_res, format!("GOOGLE:{}", user_info.email))
}
OAuthTarget::Reddit => {
// Process authorization code, expecting a token response back.
let token_res = self
.reddit_client
.exchange_code(AuthorizationCode::new(creds.creds.code))
.request_async(&self.http_client)
.await
.map_err(Self::Error::OAuth2)?;

// Use access token to request user info.
let user_info = self
.http_client
.get("https://oauth.reddit.com/api/v1/me")
.header(USER_AGENT.as_str(), "minesweeper-io")
.header(
AUTHORIZATION.as_str(),
format!("Bearer {}", token_res.access_token().secret()),
)
.send()
.await
.map_err(Self::Error::Reqwest)?
.json::<RedditUserInfo>()
.await
.map_err(Self::Error::Reqwest)?;
(token_res, format!("REDDIT:{}", user_info.name))
}
OAuthTarget::Github => {
// Process authorization code, expecting a token response back.
let token_res = self
Expand Down
8 changes: 0 additions & 8 deletions web/src/app/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ pub fn LoginForm(login: ServerAction<Login>, target: OAuthTarget) -> impl IntoVi
"bg-blue-400 text-white hover:bg-blue-600"
),
),
OAuthTarget::Reddit => (
"Reddit",
"Log in with Reddit",
button_class!(
"w-full max-w-xs h-8",
"bg-orange-600 text-white hover:bg-orange-800"
),
),
OAuthTarget::Github => (
"Github",
"Log in with Github",
Expand Down
1 change: 0 additions & 1 deletion web/src/app/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub fn LoginView(login: ServerAction<Login>) -> impl IntoView {
"Log in if you want to set your display name, keep game history, or see your game stats & trends"
</div>
<LoginForm login target=OAuthTarget::Google />
<LoginForm login target=OAuthTarget::Reddit />
<LoginForm login target=OAuthTarget::Github />
<div class="text-center pt-8 text-gray-900 dark:text-gray-100">
"Note: None of your personal info is checked or stored - only your username is used to identify your account"
Expand Down
4 changes: 0 additions & 4 deletions web/src/backend/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub fn services_router() -> Router<AppState> {
pub struct App {
pub db: SqlitePool,
pub google_client: SpecialClient,
pub reddit_client: SpecialClient,
pub github_client: SpecialClient,
pub session_store: SqliteStore,
}
Expand Down Expand Up @@ -103,7 +102,6 @@ impl App {
dotenvy::dotenv()?;

let google_client = oauth_client(OAuthTarget::Google)?;
let reddit_client = oauth_client(OAuthTarget::Reddit)?;
let github_client = oauth_client(OAuthTarget::Github)?;

let db_url = env::var("DATABASE_URL").expect("DATABASE_URL should be provided");
Expand All @@ -122,7 +120,6 @@ impl App {
Ok(Self {
db,
google_client,
reddit_client,
github_client,
session_store,
})
Expand Down Expand Up @@ -172,7 +169,6 @@ impl App {
let backend = Backend::new(
self.db.clone(),
self.google_client,
self.reddit_client,
self.github_client,
);
let auth_service = AuthManagerLayerBuilder::new(backend, session_layer).build();
Expand Down