Skip to content

Commit

Permalink
solve #16
Browse files Browse the repository at this point in the history
  • Loading branch information
eltorio committed Oct 10, 2024
1 parent cccb891 commit 8661aac
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 39 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sctgdesk-api-server"
version = "1.1.99-43"
version = "1.1.99-44"
edition = "2021"
build = "build.rs"
# [workspace]
Expand Down
4 changes: 4 additions & 0 deletions db_v2/create/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,7 @@ CREATE INDEX IF NOT EXISTS index_ab_peer_ab_deleted_at on ab_peer (ab, deleted_a
CREATE INDEX IF NOT EXISTS index_ab_rule_user on ab_rule ("user");
CREATE INDEX IF NOT EXISTS index_ab_rule_grp on ab_rule (grp);
CREATE INDEX IF NOT EXISTS index_ab_rule_ab_created_at on ab_rule (ab, created_at);

-- Needed for compilation time sqlx check
-- INSERT OR IGNORE INTO peer (guid, id, uuid, pk, created_at, "user", status, note, region, strategy, info, last_online) VALUES
-- (x'018f255622f77778a006702ca5c23715', 'TESTUSER', randomblob(16), randomblob(16), '1901-01-01 12:00:00', randomblob(16), 0, '', NULL, randomblob(16), '{}', '1901-01-01 12:00:00');
32 changes: 23 additions & 9 deletions libs/oauth2/src/github_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ pub struct GithubUser {
pub blog: String,
pub location: Option<String>,
pub email: Option<String>,
pub hireable: Option<String>,
pub hireable: Option<bool>,
pub bio: Option<String>,
pub twitter_username: Option<String>,
pub notification_email: Option<String>,
pub public_repos: u64,
pub public_gists: u64,
pub followers: u64,
Expand Down Expand Up @@ -141,32 +142,45 @@ impl OAuthProvider for GithubProvider {
.error_for_status()
.map_err(|_| Oauth2Error::ExchangeCodeError)?;

let body_text = response.text().await.map_err(|_| Oauth2Error::ExchangeCodeError)?;
let body: GithubTokenResponse = serde_json::from_str(&body_text)
let body_text = response
.text()
.await
.map_err(|_| Oauth2Error::ExchangeCodeError)?;
let body: GithubTokenResponse =
serde_json::from_str(&body_text).map_err(|_| Oauth2Error::ExchangeCodeError)?;

// Get the user info with:
// Authorization: Bearer OAUTH-TOKEN
// GET https://api.github.com/user
let response = reqwest::Client::new()
let response = reqwest::Client::new()
.get("https://api.github.com/user")
.header("Accept", "application/json")
.header("User-Agent", format!("SCTGDesk/{}", env!("CARGO_PKG_VERSION")))
.header(
"User-Agent",
format!("SCTGDesk/{}", env!("CARGO_PKG_VERSION")),
)
.header("Authorization", format!("Bearer {}", body.access_token))
.send()
.await
.map_err(|_| Oauth2Error::ExchangeCodeError)?;

let user_info_text = response.text().await.map_err(|_| Oauth2Error::ExchangeCodeError)?;
log::debug!("User info:\n {}", user_info_text);
let user_info: GithubUser = serde_json::from_str(&user_info_text)
let user_info_text = response
.text()
.await
.map_err(|_| Oauth2Error::ExchangeCodeError)?;
log::debug!("User info:\n {}", user_info_text);
let user_info: GithubUser = serde_json::from_str(&user_info_text).map_err(|e| {
log::debug!("Failed to deserialize Github user info\nGithub probably changed its json response\nYou may need to correct the struct GithubUser: {}", e);
Oauth2Error::ExchangeCodeError
})?;

if true {
Ok(OAuthResponse {
access_token: body.access_token,
username: user_info.login,
email: user_info.email.unwrap_or("tobefilled@world.com".to_string()),
email: user_info
.email
.unwrap_or("tobefilled@world.com".to_string()),
})
} else {
Err(Oauth2Error::ExchangeCodeError)
Expand Down
4 changes: 2 additions & 2 deletions webconsole/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 26 additions & 26 deletions webconsole/package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
{
"name": "sctgdesk-api-server-webconsole",
"private": false,
"version": "1.1.99-43",
"version": "1.1.99-44",
"type": "module",
"scripts": {
"build": "vite build && gulp licenses",
"devserver": "npx nodemon -V -w ./src -e js,vue,ts,css,html --exec 'npm run build && node devserver.js'",
"create-cert": "openssl req -x509 -newkey rsa:4096 -keyout localhost.key -out localhost.pem -sha256 -nodes -days 365",
"dev": "vite",
"preview": "vite preview",
"dev": "vite"
"build": "vite build && gulp licenses",
"devserver": "npx nodemon -V -w ./src -e js,vue,ts,css,html --exec 'npm run build && node devserver.js'"
},
"dependencies": {
"@headlessui/vue": "^1.7.23",
"vue-router": "^4.4.5",
"vue": "^3.5.11",
"@heroicons/vue": "^2.1.5",
"pinia": "^2.2.4",
"@pqina/flip": "^1.8.3",
"jdenticon": "^3.3.0",
"axios": "^1.7.7",
"flowbite": "^2.5.2",
"jdenticon": "^3.3.0",
"clipboard": "^2.0.11",
"vue-router": "^4.4.5",
"chart.js": "^4.4.4",
"axios": "^1.7.7"
"vue": "^3.5.11",
"@headlessui/vue": "^1.7.23",
"@heroicons/vue": "^2.1.5",
"@pqina/flip": "^1.8.3"
},
"devDependencies": {
"typescript": "^5.6.3",
"postcss": "^8.4.47",
"vite-plugin-static-copy": "^2.0.0",
"sass": "^1.79.4",
"gulp-append-prepend": "^1.0.9",
"express": "^5.0.0",
"@tailwindcss/forms": "^0.5.9",
"gulp-if": "^3.0.0",
"glob": "11.0.0",
"gulp": "^5.0.0",
"vite-plugin-static-copy": "^2.0.0",
"autoprefixer": "^10.4.20",
"@tailwindcss/typography": "^0.5.15",
"express": "^5.0.0",
"@types/glob": "^8.1.0",
"vite": "^5.4.8",
"@fullhuman/postcss-purgecss": "^6.0.0",
"@tailwindcss/forms": "^0.5.9",
"sass": "^1.79.4",
"tailwindcss": "^3.4.13",
"typescript": "^5.6.3",
"postcss": "^8.4.47",
"ts-node": "^10.9.2",
"@fullhuman/postcss-purgecss": "^6.0.0",
"vite": "^5.4.8",
"nodemon": "^3.1.7",
"@vitejs/plugin-vue": "^5.1.4",
"tailwindcss": "^3.4.13",
"postcss-purgefonts": "^1.0.2",
"@tailwindcss/typography": "^0.5.15",
"gulp": "^5.0.0",
"nodemon": "^3.1.7"
"gulp-append-prepend": "^1.0.9",
"glob": "11.0.0",
"postcss-purgefonts": "^1.0.2"
}
}

0 comments on commit 8661aac

Please sign in to comment.