Skip to content

Commit d310f48

Browse files
authored
compat login: support using client-provided device ID (#4342)
2 parents 12b3161 + a9721c2 commit d310f48

20 files changed

+431
-182
lines changed

crates/data-model/src/compat/sso_login.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@ use ulid::Ulid;
1010
use url::Url;
1111

1212
use super::CompatSession;
13-
use crate::InvalidTransitionError;
13+
use crate::{BrowserSession, InvalidTransitionError};
1414

1515
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize)]
1616
pub enum CompatSsoLoginState {
1717
#[default]
1818
Pending,
1919
Fulfilled {
2020
fulfilled_at: DateTime<Utc>,
21-
session_id: Ulid,
21+
browser_session_id: Ulid,
2222
},
2323
Exchanged {
2424
fulfilled_at: DateTime<Utc>,
2525
exchanged_at: DateTime<Utc>,
26-
session_id: Ulid,
26+
compat_session_id: Ulid,
2727
},
2828
}
2929

@@ -80,18 +80,21 @@ impl CompatSsoLoginState {
8080
}
8181
}
8282

83-
/// Get the session ID associated with the login.
83+
/// Get the compat session ID associated with the login.
8484
///
85-
/// Returns `None` if the compat SSO login state is [`Pending`].
85+
/// Returns `None` if the compat SSO login state is [`Pending`] or
86+
/// [`Fulfilled`].
8687
///
8788
/// [`Pending`]: CompatSsoLoginState::Pending
89+
/// [`Fulfilled`]: CompatSsoLoginState::Fulfilled
8890
#[must_use]
8991
pub fn session_id(&self) -> Option<Ulid> {
9092
match self {
91-
Self::Pending => None,
92-
Self::Fulfilled { session_id, .. } | Self::Exchanged { session_id, .. } => {
93-
Some(*session_id)
94-
}
93+
Self::Pending | Self::Fulfilled { .. } => None,
94+
Self::Exchanged {
95+
compat_session_id: session_id,
96+
..
97+
} => Some(*session_id),
9598
}
9699
}
97100

@@ -106,12 +109,12 @@ impl CompatSsoLoginState {
106109
pub fn fulfill(
107110
self,
108111
fulfilled_at: DateTime<Utc>,
109-
session: &CompatSession,
112+
browser_session: &BrowserSession,
110113
) -> Result<Self, InvalidTransitionError> {
111114
match self {
112115
Self::Pending => Ok(Self::Fulfilled {
113116
fulfilled_at,
114-
session_id: session.id,
117+
browser_session_id: browser_session.id,
115118
}),
116119
Self::Fulfilled { .. } | Self::Exchanged { .. } => Err(InvalidTransitionError),
117120
}
@@ -126,15 +129,19 @@ impl CompatSsoLoginState {
126129
///
127130
/// [`Fulfilled`]: CompatSsoLoginState::Fulfilled
128131
/// [`Exchanged`]: CompatSsoLoginState::Exchanged
129-
pub fn exchange(self, exchanged_at: DateTime<Utc>) -> Result<Self, InvalidTransitionError> {
132+
pub fn exchange(
133+
self,
134+
exchanged_at: DateTime<Utc>,
135+
compat_session: &CompatSession,
136+
) -> Result<Self, InvalidTransitionError> {
130137
match self {
131138
Self::Fulfilled {
132139
fulfilled_at,
133-
session_id,
140+
browser_session_id: _,
134141
} => Ok(Self::Exchanged {
135142
fulfilled_at,
136143
exchanged_at,
137-
session_id,
144+
compat_session_id: compat_session.id,
138145
}),
139146
Self::Pending { .. } | Self::Exchanged { .. } => Err(InvalidTransitionError),
140147
}
@@ -171,9 +178,9 @@ impl CompatSsoLogin {
171178
pub fn fulfill(
172179
mut self,
173180
fulfilled_at: DateTime<Utc>,
174-
session: &CompatSession,
181+
browser_session: &BrowserSession,
175182
) -> Result<Self, InvalidTransitionError> {
176-
self.state = self.state.fulfill(fulfilled_at, session)?;
183+
self.state = self.state.fulfill(fulfilled_at, browser_session)?;
177184
Ok(self)
178185
}
179186

@@ -186,8 +193,12 @@ impl CompatSsoLogin {
186193
///
187194
/// [`Fulfilled`]: CompatSsoLoginState::Fulfilled
188195
/// [`Exchanged`]: CompatSsoLoginState::Exchanged
189-
pub fn exchange(mut self, exchanged_at: DateTime<Utc>) -> Result<Self, InvalidTransitionError> {
190-
self.state = self.state.exchange(exchanged_at)?;
196+
pub fn exchange(
197+
mut self,
198+
exchanged_at: DateTime<Utc>,
199+
compat_session: &CompatSession,
200+
) -> Result<Self, InvalidTransitionError> {
201+
self.state = self.state.exchange(exchanged_at, compat_session)?;
191202
Ok(self)
192203
}
193204
}

0 commit comments

Comments
 (0)