@@ -10,20 +10,20 @@ use ulid::Ulid;
10
10
use url:: Url ;
11
11
12
12
use super :: CompatSession ;
13
- use crate :: InvalidTransitionError ;
13
+ use crate :: { BrowserSession , InvalidTransitionError } ;
14
14
15
15
#[ derive( Debug , Clone , Default , PartialEq , Eq , Serialize ) ]
16
16
pub enum CompatSsoLoginState {
17
17
#[ default]
18
18
Pending ,
19
19
Fulfilled {
20
20
fulfilled_at : DateTime < Utc > ,
21
- session_id : Ulid ,
21
+ browser_session_id : Ulid ,
22
22
} ,
23
23
Exchanged {
24
24
fulfilled_at : DateTime < Utc > ,
25
25
exchanged_at : DateTime < Utc > ,
26
- session_id : Ulid ,
26
+ compat_session_id : Ulid ,
27
27
} ,
28
28
}
29
29
@@ -80,18 +80,21 @@ impl CompatSsoLoginState {
80
80
}
81
81
}
82
82
83
- /// Get the session ID associated with the login.
83
+ /// Get the compat session ID associated with the login.
84
84
///
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`].
86
87
///
87
88
/// [`Pending`]: CompatSsoLoginState::Pending
89
+ /// [`Fulfilled`]: CompatSsoLoginState::Fulfilled
88
90
#[ must_use]
89
91
pub fn session_id ( & self ) -> Option < Ulid > {
90
92
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) ,
95
98
}
96
99
}
97
100
@@ -106,12 +109,12 @@ impl CompatSsoLoginState {
106
109
pub fn fulfill (
107
110
self ,
108
111
fulfilled_at : DateTime < Utc > ,
109
- session : & CompatSession ,
112
+ browser_session : & BrowserSession ,
110
113
) -> Result < Self , InvalidTransitionError > {
111
114
match self {
112
115
Self :: Pending => Ok ( Self :: Fulfilled {
113
116
fulfilled_at,
114
- session_id : session . id ,
117
+ browser_session_id : browser_session . id ,
115
118
} ) ,
116
119
Self :: Fulfilled { .. } | Self :: Exchanged { .. } => Err ( InvalidTransitionError ) ,
117
120
}
@@ -126,15 +129,19 @@ impl CompatSsoLoginState {
126
129
///
127
130
/// [`Fulfilled`]: CompatSsoLoginState::Fulfilled
128
131
/// [`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 > {
130
137
match self {
131
138
Self :: Fulfilled {
132
139
fulfilled_at,
133
- session_id ,
140
+ browser_session_id : _ ,
134
141
} => Ok ( Self :: Exchanged {
135
142
fulfilled_at,
136
143
exchanged_at,
137
- session_id ,
144
+ compat_session_id : compat_session . id ,
138
145
} ) ,
139
146
Self :: Pending { .. } | Self :: Exchanged { .. } => Err ( InvalidTransitionError ) ,
140
147
}
@@ -171,9 +178,9 @@ impl CompatSsoLogin {
171
178
pub fn fulfill (
172
179
mut self ,
173
180
fulfilled_at : DateTime < Utc > ,
174
- session : & CompatSession ,
181
+ browser_session : & BrowserSession ,
175
182
) -> Result < Self , InvalidTransitionError > {
176
- self . state = self . state . fulfill ( fulfilled_at, session ) ?;
183
+ self . state = self . state . fulfill ( fulfilled_at, browser_session ) ?;
177
184
Ok ( self )
178
185
}
179
186
@@ -186,8 +193,12 @@ impl CompatSsoLogin {
186
193
///
187
194
/// [`Fulfilled`]: CompatSsoLoginState::Fulfilled
188
195
/// [`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) ?;
191
202
Ok ( self )
192
203
}
193
204
}
0 commit comments