Skip to content

Commit 64399bd

Browse files
sshaderConvex, Inc.
authored andcommitted
Fallback on email in the token if Auth0 userinfo fails (#36347)
We fetch userinfo from Auth0 on new accounts. The thing we really need is an email (name + nickname are optional and nice to have). This isn't possible for some of our external apps (Chef), so fallback on taking the email from the validated access token instead. GitOrigin-RevId: 8650f40bb0d90456bcfbae1a89f7b8f8ed48d545
1 parent b13df2f commit 64399bd

File tree

1 file changed

+21
-1
lines changed
  • crates/authentication/src

1 file changed

+21
-1
lines changed

crates/authentication/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,35 @@ pub struct ConsoleClaims {
225225
pub struct ConsoleAccessToken {
226226
email: String,
227227
sub: String,
228+
name: Option<String>,
229+
nickname: Option<String>,
228230
}
229231
impl ConsoleAccessToken {
230232
#[cfg(any(test, feature = "testing"))]
231233
pub fn new(email: String, sub: String) -> Self {
232-
Self { email, sub }
234+
Self {
235+
email,
236+
sub,
237+
name: None,
238+
nickname: None,
239+
}
233240
}
234241

235242
pub fn email(&self) -> &str {
236243
&self.email
237244
}
238245
}
239246

247+
impl From<ConsoleAccessToken> for UserInfo {
248+
fn from(value: ConsoleAccessToken) -> Self {
249+
Self {
250+
email: value.email,
251+
name: value.name,
252+
nickname: value.nickname,
253+
}
254+
}
255+
}
256+
240257
#[derive(Deserialize, Clone)]
241258
/// Relevant fields returned from the Auth0 userinfo endpoint
242259
pub struct UserInfo {
@@ -400,6 +417,9 @@ where
400417
.as_ref()
401418
.expect("Already validated subject is present")
402419
.to_owned(),
420+
// TODO(sarah) read these from the token if possible
421+
nickname: None,
422+
name: None,
403423
})
404424
}
405425

0 commit comments

Comments
 (0)