@@ -30,6 +30,12 @@ pub enum UpstreamOAuthAuthorizationSessionState {
30
30
extra_callback_parameters : Option < serde_json:: Value > ,
31
31
userinfo : Option < serde_json:: Value > ,
32
32
} ,
33
+ Unlinked {
34
+ completed_at : DateTime < Utc > ,
35
+ consumed_at : Option < DateTime < Utc > > ,
36
+ unlinked_at : DateTime < Utc > ,
37
+ id_token : Option < String > ,
38
+ } ,
33
39
}
34
40
35
41
impl UpstreamOAuthAuthorizationSessionState {
@@ -57,7 +63,9 @@ impl UpstreamOAuthAuthorizationSessionState {
57
63
extra_callback_parameters,
58
64
userinfo,
59
65
} ) ,
60
- Self :: Completed { .. } | Self :: Consumed { .. } => Err ( InvalidTransitionError ) ,
66
+ Self :: Completed { .. } | Self :: Consumed { .. } | Self :: Unlinked { .. } => {
67
+ Err ( InvalidTransitionError )
68
+ }
61
69
}
62
70
}
63
71
@@ -85,7 +93,9 @@ impl UpstreamOAuthAuthorizationSessionState {
85
93
extra_callback_parameters,
86
94
userinfo,
87
95
} ) ,
88
- Self :: Pending | Self :: Consumed { .. } => Err ( InvalidTransitionError ) ,
96
+ Self :: Pending | Self :: Consumed { .. } | Self :: Unlinked { .. } => {
97
+ Err ( InvalidTransitionError )
98
+ }
89
99
}
90
100
}
91
101
@@ -98,7 +108,7 @@ impl UpstreamOAuthAuthorizationSessionState {
98
108
#[ must_use]
99
109
pub fn link_id ( & self ) -> Option < Ulid > {
100
110
match self {
101
- Self :: Pending => None ,
111
+ Self :: Pending | Self :: Unlinked { .. } => None ,
102
112
Self :: Completed { link_id, .. } | Self :: Consumed { link_id, .. } => Some ( * link_id) ,
103
113
}
104
114
}
@@ -114,9 +124,9 @@ impl UpstreamOAuthAuthorizationSessionState {
114
124
pub fn completed_at ( & self ) -> Option < DateTime < Utc > > {
115
125
match self {
116
126
Self :: Pending => None ,
117
- Self :: Completed { completed_at, .. } | Self :: Consumed { completed_at , .. } => {
118
- Some ( * completed_at)
119
- }
127
+ Self :: Completed { completed_at, .. }
128
+ | Self :: Consumed { completed_at, .. }
129
+ | Self :: Unlinked { completed_at , .. } => Some ( * completed_at ) ,
120
130
}
121
131
}
122
132
@@ -130,9 +140,9 @@ impl UpstreamOAuthAuthorizationSessionState {
130
140
pub fn id_token ( & self ) -> Option < & str > {
131
141
match self {
132
142
Self :: Pending => None ,
133
- Self :: Completed { id_token, .. } | Self :: Consumed { id_token , .. } => {
134
- id_token. as_deref ( )
135
- }
143
+ Self :: Completed { id_token, .. }
144
+ | Self :: Consumed { id_token, .. }
145
+ | Self :: Unlinked { id_token , .. } => id_token . as_deref ( ) ,
136
146
}
137
147
}
138
148
@@ -145,7 +155,7 @@ impl UpstreamOAuthAuthorizationSessionState {
145
155
#[ must_use]
146
156
pub fn extra_callback_parameters ( & self ) -> Option < & serde_json:: Value > {
147
157
match self {
148
- Self :: Pending => None ,
158
+ Self :: Pending | Self :: Unlinked { .. } => None ,
149
159
Self :: Completed {
150
160
extra_callback_parameters,
151
161
..
@@ -160,7 +170,7 @@ impl UpstreamOAuthAuthorizationSessionState {
160
170
#[ must_use]
161
171
pub fn userinfo ( & self ) -> Option < & serde_json:: Value > {
162
172
match self {
163
- Self :: Pending => None ,
173
+ Self :: Pending | Self :: Unlinked { .. } => None ,
164
174
Self :: Completed { userinfo, .. } | Self :: Consumed { userinfo, .. } => userinfo. as_ref ( ) ,
165
175
}
166
176
}
@@ -177,6 +187,22 @@ impl UpstreamOAuthAuthorizationSessionState {
177
187
match self {
178
188
Self :: Pending | Self :: Completed { .. } => None ,
179
189
Self :: Consumed { consumed_at, .. } => Some ( * consumed_at) ,
190
+ Self :: Unlinked { consumed_at, .. } => * consumed_at,
191
+ }
192
+ }
193
+
194
+ /// Get the time at which the upstream OAuth 2.0 authorization session was
195
+ /// unlinked.
196
+ ///
197
+ /// Returns `None` if the upstream OAuth 2.0 authorization session state is
198
+ /// not [`Unlinked`].
199
+ ///
200
+ /// [`Unlinked`]: UpstreamOAuthAuthorizationSessionState::Unlinked
201
+ #[ must_use]
202
+ pub fn unlinked_at ( & self ) -> Option < DateTime < Utc > > {
203
+ match self {
204
+ Self :: Pending | Self :: Completed { .. } | Self :: Consumed { .. } => None ,
205
+ Self :: Unlinked { unlinked_at, .. } => Some ( * unlinked_at) ,
180
206
}
181
207
}
182
208
@@ -206,6 +232,15 @@ impl UpstreamOAuthAuthorizationSessionState {
206
232
pub fn is_consumed ( & self ) -> bool {
207
233
matches ! ( self , Self :: Consumed { .. } )
208
234
}
235
+
236
+ /// Returns `true` if the upstream OAuth 2.0 authorization session state is
237
+ /// [`Unlinked`].
238
+ ///
239
+ /// [`Unlinked`]: UpstreamOAuthAuthorizationSessionState::Unlinked
240
+ #[ must_use]
241
+ pub fn is_unlinked ( & self ) -> bool {
242
+ matches ! ( self , Self :: Unlinked { .. } )
243
+ }
209
244
}
210
245
211
246
#[ derive( Debug , Clone , PartialEq , Eq , Serialize ) ]
0 commit comments