Skip to content

Commit 2a6a904

Browse files
committed
Extract into top level const
1 parent 6371b57 commit 2a6a904

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

server/src/handlers.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ const PREFIX_META: &str = "x-p-meta-";
2424
const STREAM_NAME_HEADER_KEY: &str = "x-p-stream";
2525
const FILL_NULL_OPTION_KEY: &str = "send_null";
2626
const SEPARATOR: char = '^';
27+
28+
const OIDC_SCOPE: &str = "openid profile email";
29+
const COOKIE_AGE_DAYS: usize = 7;
30+
const SESSION_COOKIE_NAME: &str = "session";
31+
const USER_COOKIE_NAME: &str = "username";

server/src/handlers/http/oidc.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use ulid::Ulid;
3131
use url::Url;
3232

3333
use crate::{
34+
handlers::{COOKIE_AGE_DAYS, OIDC_SCOPE, SESSION_COOKIE_NAME, USER_COOKIE_NAME},
3435
oidc::{Claims, DiscoveredClient},
3536
option::CONFIG,
3637
rbac::{
@@ -42,10 +43,6 @@ use crate::{
4243
utils::actix::extract_session_key_from_req,
4344
};
4445

45-
// fetch common personalization scope to determine username.
46-
const SCOPE: &str = "openid profile email";
47-
const COOKIE_AGE_DAYS: usize = 7;
48-
4946
/// Struct representing query params returned from oidc provider
5047
#[derive(Deserialize, Debug)]
5148
pub struct Login {
@@ -182,7 +179,7 @@ fn redirect_to_oidc(
182179
) -> HttpResponse {
183180
let redirect = query.into_inner().redirect.to_string();
184181
let auth_url = oidc_client.auth_url(&Options {
185-
scope: Some(SCOPE.into()),
182+
scope: Some(OIDC_SCOPE.into()),
186183
state: Some(redirect),
187184
..Default::default()
188185
});
@@ -222,7 +219,7 @@ fn redirect_no_oauth_setup(mut url: Url) -> HttpResponse {
222219
}
223220

224221
fn cookie_session(id: Ulid) -> Cookie<'static> {
225-
let authorization_cookie = Cookie::build("session", id.to_string())
222+
let authorization_cookie = Cookie::build(SESSION_COOKIE_NAME, id.to_string())
226223
.max_age(time::Duration::days(COOKIE_AGE_DAYS as i64))
227224
.same_site(SameSite::Strict)
228225
.path("/")
@@ -231,7 +228,7 @@ fn cookie_session(id: Ulid) -> Cookie<'static> {
231228
}
232229

233230
fn cookie_username(username: &str) -> Cookie<'static> {
234-
let authorization_cookie = Cookie::build("username", username.to_string())
231+
let authorization_cookie = Cookie::build(USER_COOKIE_NAME, username.to_string())
235232
.max_age(time::Duration::days(COOKIE_AGE_DAYS as i64))
236233
.same_site(SameSite::Strict)
237234
.path("/")

0 commit comments

Comments
 (0)