Skip to content

Commit 17413b3

Browse files
atrakhConvex, Inc.
authored andcommitted
Add middleware to require SSO for login if the flag is require_sso_flag is set (#42410)
GitOrigin-RevId: 7140fc94419df99ba2db4de3dc70b0e72f6d3113
1 parent 6e987a9 commit 17413b3

File tree

4 files changed

+111
-13
lines changed

4 files changed

+111
-13
lines changed

crates/authentication/src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ use biscuit::{
1515
JWT,
1616
};
1717
use chrono::TimeZone;
18-
use common::auth::AuthInfo;
18+
use common::{
19+
auth::AuthInfo,
20+
types::TeamId,
21+
};
1922
use data_url::DataUrl;
2023
use errors::ErrorMetadata;
2124
use futures::Future;
@@ -492,6 +495,8 @@ pub struct WorkOSClaims {
492495

493496
#[serde(flatten)]
494497
vercel: Option<VercelClaims>,
498+
499+
sso_team_id: Option<String>,
495500
}
496501

497502
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
@@ -536,6 +541,7 @@ pub struct ConsoleAccessToken {
536541
sub: String,
537542
name: Option<String>,
538543
vercel: Option<VercelClaims>,
544+
sso_team_id: Option<TeamId>,
539545
}
540546

541547
impl ConsoleAccessToken {
@@ -546,6 +552,7 @@ impl ConsoleAccessToken {
546552
sub,
547553
name: None,
548554
vercel: None,
555+
sso_team_id: None,
549556
}
550557
}
551558

@@ -596,6 +603,7 @@ pub struct AuthenticatedLogin {
596603
email: Option<String>,
597604
sub: String,
598605
user_info: Option<UserInfo>,
606+
sso_team_id: Option<TeamId>,
599607
}
600608

601609
impl AuthenticatedLogin {
@@ -604,6 +612,7 @@ impl AuthenticatedLogin {
604612
email: token.email,
605613
sub: token.sub,
606614
user_info,
615+
sso_team_id: token.sso_team_id,
607616
}
608617
}
609618

@@ -622,6 +631,10 @@ impl AuthenticatedLogin {
622631
pub fn vercel_info(&self) -> Option<&VercelClaims> {
623632
self.user_info.as_ref().and_then(|ui| ui.vercel_info())
624633
}
634+
635+
pub fn sso_team_id(&self) -> Option<TeamId> {
636+
self.sso_team_id
637+
}
625638
}
626639

627640
pub fn names_to_full_name(first_name: Option<String>, last_name: Option<String>) -> Option<String> {
@@ -766,6 +779,12 @@ where
766779
email: claims.private.email.clone(),
767780
sub,
768781
vercel: claims.private.vercel.clone(),
782+
sso_team_id: claims
783+
.private
784+
.sso_team_id
785+
.as_ref()
786+
.map(|id| id.parse().map(TeamId))
787+
.transpose()?,
769788
name: full_name,
770789
})
771790
}
@@ -1019,6 +1038,7 @@ mod tests {
10191038
first_name: Some("Test".to_string()),
10201039
last_name: Some("User".to_string()),
10211040
vercel: None,
1041+
sso_team_id: None,
10221042
},
10231043
),
10241044
&*TEST_SIGNING_KEY,
@@ -1071,6 +1091,7 @@ mod tests {
10711091
first_name: Some("Test".to_string()),
10721092
last_name: Some("User2".to_string()),
10731093
vercel: None,
1094+
sso_team_id: None,
10741095
},
10751096
),
10761097
&*TEST_SIGNING_KEY,

npm-packages/convex/management-openapi.json

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"schema": {
2222
"type": "array",
2323
"items": {
24-
"$ref": "#/components/schemas/Team"
24+
"$ref": "#/components/schemas/TeamResponse"
2525
}
2626
}
2727
}
@@ -397,7 +397,15 @@
397397
"ReferralCode": {
398398
"type": "string"
399399
},
400-
"Team": {
400+
"TeamId": {
401+
"type": "integer",
402+
"format": "int64",
403+
"minimum": 0
404+
},
405+
"TeamName": {
406+
"type": "string"
407+
},
408+
"TeamResponse": {
401409
"type": "object",
402410
"required": [
403411
"id",
@@ -445,19 +453,17 @@
445453
"slug": {
446454
"$ref": "#/components/schemas/TeamSlug"
447455
},
456+
"ssoLoginId": {
457+
"type": [
458+
"string",
459+
"null"
460+
]
461+
},
448462
"suspended": {
449463
"type": "boolean"
450464
}
451465
}
452466
},
453-
"TeamId": {
454-
"type": "integer",
455-
"format": "int64",
456-
"minimum": 0
457-
},
458-
"TeamName": {
459-
"type": "string"
460-
},
461467
"TeamSlug": {
462468
"type": "string"
463469
}

npm-packages/dashboard/dashboard-management-openapi.json

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
"schema": {
245245
"type": "array",
246246
"items": {
247-
"$ref": "#/components/schemas/Team"
247+
"$ref": "#/components/schemas/TeamResponse"
248248
}
249249
}
250250
}
@@ -5531,6 +5531,65 @@
55315531
"TeamName": {
55325532
"type": "string"
55335533
},
5534+
"TeamResponse": {
5535+
"type": "object",
5536+
"required": [
5537+
"id",
5538+
"name",
5539+
"slug",
5540+
"suspended",
5541+
"referralCode"
5542+
],
5543+
"properties": {
5544+
"creator": {
5545+
"oneOf": [
5546+
{
5547+
"type": "null"
5548+
},
5549+
{
5550+
"$ref": "#/components/schemas/MemberId"
5551+
}
5552+
]
5553+
},
5554+
"id": {
5555+
"$ref": "#/components/schemas/TeamId"
5556+
},
5557+
"managedBy": {
5558+
"type": [
5559+
"string",
5560+
"null"
5561+
]
5562+
},
5563+
"name": {
5564+
"$ref": "#/components/schemas/TeamName"
5565+
},
5566+
"referralCode": {
5567+
"$ref": "#/components/schemas/ReferralCode"
5568+
},
5569+
"referredBy": {
5570+
"oneOf": [
5571+
{
5572+
"type": "null"
5573+
},
5574+
{
5575+
"$ref": "#/components/schemas/TeamId"
5576+
}
5577+
]
5578+
},
5579+
"slug": {
5580+
"$ref": "#/components/schemas/TeamSlug"
5581+
},
5582+
"ssoLoginId": {
5583+
"type": [
5584+
"string",
5585+
"null"
5586+
]
5587+
},
5588+
"suspended": {
5589+
"type": "boolean"
5590+
}
5591+
}
5592+
},
55345593
"TeamSlug": {
55355594
"type": "string"
55365595
},

npm-packages/dashboard/src/generatedApi.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2370,6 +2370,17 @@ export interface components {
23702370
role: components["schemas"]["Role"];
23712371
};
23722372
TeamName: string;
2373+
TeamResponse: {
2374+
creator?: null | components["schemas"]["MemberId"];
2375+
id: components["schemas"]["TeamId"];
2376+
managedBy?: string | null;
2377+
name: components["schemas"]["TeamName"];
2378+
referralCode: components["schemas"]["ReferralCode"];
2379+
referredBy?: null | components["schemas"]["TeamId"];
2380+
slug: components["schemas"]["TeamSlug"];
2381+
ssoLoginId?: string | null;
2382+
suspended: boolean;
2383+
};
23732384
TeamSlug: string;
23742385
TeamUsageStateResponse: {
23752386
teamId: components["schemas"]["TeamId"];
@@ -2594,6 +2605,7 @@ export type TeamEntitlementsResponse = components['schemas']['TeamEntitlementsRe
25942605
export type TeamId = components['schemas']['TeamId'];
25952606
export type TeamMemberResponse = components['schemas']['TeamMemberResponse'];
25962607
export type TeamName = components['schemas']['TeamName'];
2608+
export type TeamResponse = components['schemas']['TeamResponse'];
25972609
export type TeamSlug = components['schemas']['TeamSlug'];
25982610
export type TeamUsageStateResponse = components['schemas']['TeamUsageStateResponse'];
25992611
export type TransferProjectArgs = components['schemas']['TransferProjectArgs'];
@@ -2873,7 +2885,7 @@ export interface operations {
28732885
[name: string]: unknown;
28742886
};
28752887
content: {
2876-
"application/json": components["schemas"]["Team"][];
2888+
"application/json": components["schemas"]["TeamResponse"][];
28772889
};
28782890
};
28792891
};

0 commit comments

Comments
 (0)