Skip to content

Commit e531766

Browse files
committed
Keep working it
1 parent c413017 commit e531766

File tree

6 files changed

+89
-59
lines changed

6 files changed

+89
-59
lines changed

backend/.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ GAMMA_INTERNAL_URL=http://localhost:8081
77
GAMMA_API_KEY=hubbit
88
GAMMA_CLIENT_ID=hubbit
99
GAMMA_CLIENT_SECRET=hubbit
10+
GAMMA_REDIRECT_URI=http://localhost:3000/api/auth/gamma/callback
1011

1112
COOKIE_SECRET=bdvrJ2cYgPeaj6Tys5475QHoj7Qcenb2bdvrJ2cYgPeaj6Tys5475QHoj7Qcenb2
1213
COOKIE_SECURE=false

backend/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Config {
1010
pub gamma_api_key: String,
1111
pub gamma_client_id: String,
1212
pub gamma_client_secret: String,
13+
pub gamma_redirect_uri: String,
1314
pub cookie_secret: String,
1415
pub cookie_secure: bool,
1516
pub group_whitelist: Vec<String>,
@@ -26,6 +27,7 @@ impl Config {
2627
gamma_api_key: try_read_var("GAMMA_API_KEY")?,
2728
gamma_client_id: try_read_var("GAMMA_CLIENT_ID")?,
2829
gamma_client_secret: try_read_var("GAMMA_CLIENT_SECRET")?,
30+
gamma_redirect_uri: try_read_var("GAMMA_REIDRECT_URI")?,
2931
cookie_secret: try_read_var("COOKIE_SECRET")?,
3032
cookie_secure: try_read_var("COOKIE_SECURE")?,
3133
group_whitelist: try_read_var::<String>("GROUP_WHITELIST")

backend/src/handlers/auth.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,11 @@ async fn gamma_init_flow(
5757
}
5858
}
5959

60-
// TODO: these should be config params
6160
let scope = "openid%20profile";
62-
let redirect_uri = "http://localhost:3000/api/auth/gamma/callback";
6361

6462
let url = format!(
65-
"{}/oauth2/authorize?response_type=code&client_id={}&state={}&scope={scope}&redirect_uri={redirect_uri}",
66-
config.gamma_public_url, config.gamma_client_id, state
63+
"{}/oauth2/authorize?response_type=code&client_id={}&state={}&scope={scope}&redirect_uri={}",
64+
config.gamma_public_url, config.gamma_client_id, state, config.gamma_redirect_uri
6765
);
6866
HttpResponse::TemporaryRedirect()
6967
.append_header(("Location", url))

backend/src/models.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,55 @@ impl From<Period> for i32 {
9999

100100
#[derive(Clone, Debug, Deserialize, Serialize)]
101101
pub struct GammaUser {
102+
#[serde(rename = "sub")]
102103
pub id: Uuid,
103104
pub cid: String,
105+
#[serde(rename = "nickname")]
104106
pub nick: String,
105-
#[serde(rename = "firstName")]
107+
#[serde(rename = "given_name")]
106108
pub first_name: String,
107-
#[serde(rename = "lastName")]
109+
#[serde(rename = "family_name")]
108110
pub last_name: String,
109-
#[serde(rename = "avatarUrl")]
111+
#[serde(rename = "picture")]
110112
pub avatar_url: String,
111-
pub groups: Vec<GammaGroup>,
112113
}
113114

114115
#[derive(Clone, Debug, Deserialize, Serialize)]
116+
#[serde(rename_all = "camelCase")]
115117
pub struct GammaGroup {
116-
pub active: bool,
117-
#[serde(rename = "superGroup")]
118+
pub id: Uuid,
119+
pub name: String,
120+
pub pretty_name: String,
118121
pub super_group: GammaSuperGroup,
122+
pub post: GammaGroupPost,
119123
}
120124

121-
#[derive(Clone, Debug, Deserialize, Serialize)]
125+
#[derive(Debug, Clone, Deserialize, Serialize)]
126+
#[serde(rename_all = "camelCase")]
122127
pub struct GammaSuperGroup {
123128
pub id: Uuid,
124129
pub name: String,
125-
#[serde(rename = "prettyName")]
126130
pub pretty_name: String,
131+
#[serde(rename = "type")]
132+
pub group_type: GammaGroupType,
133+
pub sv_description: String,
134+
pub en_description: String,
135+
}
136+
137+
#[derive(Debug, Clone, Deserialize, Serialize)]
138+
#[serde(rename = "camelCase")]
139+
pub enum GammaGroupType {
140+
Society,
141+
Functionaries,
142+
Committee,
143+
Alumni,
144+
}
145+
146+
#[derive(Debug, Clone, Deserialize, Serialize)]
147+
#[serde(rename_all = "camelCase")]
148+
pub struct GammaGroupPost {
149+
pub id: Uuid,
150+
pub version: u32,
151+
pub sv_name: String,
152+
pub en_name: String,
127153
}

backend/src/utils/gamma.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ struct GammaTokenRequest {
2020
pub async fn oauth2_token(config: &Config, code: &str) -> HubbitResult<GammaTokenResponse> {
2121
let client = Client::new();
2222

23-
// TODO: THis should be a config param
24-
let redirect_uri = "http://localhost:3000/api/auth/gamma/callback";
25-
2623
let url = format!("{}/oauth2/token", config.gamma_internal_url);
2724

2825
let body_str = client
@@ -31,7 +28,7 @@ pub async fn oauth2_token(config: &Config, code: &str) -> HubbitResult<GammaToke
3128
client_id: config.gamma_client_id.clone(),
3229
client_secret: config.gamma_client_secret.clone(),
3330
code: code.into(),
34-
redirect_uri: redirect_uri.into(),
31+
redirect_uri: config.gamma_redirect_uri.clone(),
3532
grant_type: "authorization_code".into(),
3633
})
3734
.header("accept", "application/json")

docker-compose.yml

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ services:
2020
PORT: 8080
2121
DATABASE_URL: postgres://hubbit:hubbit@hubbit-db/hubbit
2222
REDIS_URL: redis://hubbit-redis:6379
23-
GAMMA_PUBLIC_URL: http://localhost:8081
24-
GAMMA_INTERNAL_URL: http://gamma-backend:3000
25-
GAMMA_API_KEY: hubbit
26-
GAMMA_CLIENT_ID: hubbit
27-
GAMMA_CLIENT_SECRET: hubbit
28-
COOKIE_SECRET: QkAbEaSuT5UNDthgnScWhQwET7HzHUzFPhrS62xwYUwvtbx2ihmQanSSML2Ky63r
29-
COOKIE_SECURE: "false"
23+
# GAMMA_PUBLIC_URL: http://localhost:8081
24+
GAMMA_PUBLIC_URL: https://auth.chalmers.it
25+
# GAMMA_INTERNAL_URL: http://gamma-backend:3000
26+
GAMMA_INTERNAL_URL: https://auth.chalmers.it
27+
# GAMMA_API_KEY: hubbit
28+
# GAMMA_CLIENT_ID: hubbit
29+
# GAMMA_CLIENT_SECRET: hubbit
30+
GAMMA_API_KEY: 09a772ea-ba92-4ff9-b325-3f734abd9269:fjFwfa8flNtAt2hbCRE9Ca2dT1FWrlkR
31+
GAMMA_CLIENT_ID: GKXA9NJALIU4MLTEW2LA8BQA1X4A6X
32+
GAMMA_CLIENT_SECRET: dnW2HjRE9stNUdFlOkqCs4Za1eClsfEY
33+
GAMMA_REDIRECT_URI: http://localhost:3000/api/auth/gamma/callback
34+
COOKIE_SECRET: vVQvsmpCkHLuleJthaEd5KhCC23mnW3W5RGSNGQOru6Y32VBrddDJEMNSXGXiKeqWhTEOAQRlfYtYjbuLMY1N2PuDbOaMzx7UPpt6Ejnm2Rq4C3Wwew8wlLbMHOt14SQ
35+
COOKIE_SECURE: true
3036
RUST_LOG: ${BACKEND_LOG_LEVEL}
3137
GROUP_WHITELIST: ${GROUP_WHITELIST}
3238
ports:
@@ -64,45 +70,45 @@ services:
6470
volumes:
6571
- /settings
6672

67-
gamma-frontend:
68-
image: cthit/gamma-frontend:development
69-
environment:
70-
HTTP_PROXY: http://gamma-backend:3000
71-
ports:
72-
- ${LOCAL_GAMMA_FRONTEND_PORT}:3000
73+
# gamma-frontend:
74+
# image: cthit/gamma-frontend:development
75+
# environment:
76+
# HTTP_PROXY: http://gamma-backend:3000
77+
# ports:
78+
# - ${LOCAL_GAMMA_FRONTEND_PORT}:3000
7379

74-
gamma-backend:
75-
image: cthit/gamma-backend
76-
environment:
77-
# Default admin user name = admin
78-
# Default admin password = password
80+
# gamma-backend:
81+
# image: cthit/gamma-backend
82+
# environment:
83+
# # Default admin user name = admin
84+
# # Default admin password = password
7985

80-
DB_USER: gamma
81-
DB_PASSWORD: gamma
82-
DB_HOST: gamma-db
83-
DB_PORT: 5432
84-
DB_NAME: gamma
86+
# DB_USER: gamma
87+
# DB_PASSWORD: gamma
88+
# DB_HOST: gamma-db
89+
# DB_PORT: 5432
90+
# DB_NAME: gamma
8591

86-
REDIS_HOST: gamma-redis
87-
REDIS_PASSWORD: ""
88-
REDIS_PORT: 6379
92+
# REDIS_HOST: gamma-redis
93+
# REDIS_PASSWORD: ""
94+
# REDIS_PORT: 6379
8995

90-
SERVER_PORT: 3000
91-
SUCCESSFUL_LOGIN: http://localhost:${LOCAL_GAMMA_FRONTEND_PORT}
92-
CORS_ALLOWED_ORIGIN: http://localhost:${LOCAL_GAMMA_FRONTEND_PORT}
93-
BACKEND_URI: http://localhost:${LOCAL_GAMMA_BACKEND_PORT}/api/
94-
PRODUCTION: "false"
95-
COOKIE_DOMAIN: localhost
96-
IS_MOCKING: "true"
97-
ports:
98-
- ${LOCAL_GAMMA_BACKEND_PORT}:3000
96+
# SERVER_PORT: 3000
97+
# SUCCESSFUL_LOGIN: http://localhost:${LOCAL_GAMMA_FRONTEND_PORT}
98+
# CORS_ALLOWED_ORIGIN: http://localhost:${LOCAL_GAMMA_FRONTEND_PORT}
99+
# BACKEND_URI: http://localhost:${LOCAL_GAMMA_BACKEND_PORT}/api/
100+
# PRODUCTION: "false"
101+
# COOKIE_DOMAIN: localhost
102+
# IS_MOCKING: "true"
103+
# ports:
104+
# - ${LOCAL_GAMMA_BACKEND_PORT}:3000
99105

100-
gamma-redis:
101-
image: redis:5.0
106+
# gamma-redis:
107+
# image: redis:5.0
102108

103-
gamma-db:
104-
image: postgres:10
105-
environment:
106-
POSTGRES_USER: gamma
107-
POSTGRES_DB: gamma
108-
POSTGRES_PASSWORD: gamma
109+
# gamma-db:
110+
# image: postgres:10
111+
# environment:
112+
# POSTGRES_USER: gamma
113+
# POSTGRES_DB: gamma
114+
# POSTGRES_PASSWORD: gamma

0 commit comments

Comments
 (0)