File tree Expand file tree Collapse file tree 5 files changed +29
-6
lines changed
packages/service-utils/src Expand file tree Collapse file tree 5 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -16,14 +16,17 @@ export type PolicyResult = {
1616
1717export type CoreServiceConfig = {
1818 apiUrl : string ;
19- serviceScope : ServiceName ;
19+ // if EXPLICTLY set to null, service will not be checked for authorization
20+ // this is meant for services that are not possible to be turned off by users, such as "social" and "analytics"
21+ serviceScope : ServiceName | null ;
2022 serviceApiKey : string ;
2123 serviceAction ?: string ;
2224 useWalletAuth ?: boolean ;
2325 includeUsage ?: boolean ;
2426} ;
2527
2628export type TeamAndProjectResponse = {
29+ authMethod : "secretKey" | "publishableKey" | "jwt" | "teamId" ;
2730 team : TeamResponse ;
2831 project ?: ProjectResponse | null ;
2932} ;
@@ -42,11 +45,11 @@ export type TeamResponse = {
4245 name : string ;
4346 slug : string ;
4447 image : string | null ;
45- billingPlan : string ;
48+ billingPlan : "free" | "starter" | "growth" | "pro" ;
4649 createdAt : Date ;
4750 updatedAt : Date | null ;
4851 billingEmail : string | null ;
49- billingStatus : string | null ;
52+ billingStatus : "noPayment" | "validPayment" | "invalidPayment" | null ;
5053 growthTrialEligible : boolean | null ;
5154 enabledScopes : ServiceName [ ] ;
5255} ;
Original file line number Diff line number Diff line change @@ -12,18 +12,25 @@ export function authorizeClient(
1212 teamAndProjectResponse : TeamAndProjectResponse ,
1313) : AuthorizationResult {
1414 const { origin, bundleId } = authOptions ;
15- const { team, project } = teamAndProjectResponse ;
15+ const { team, project, authMethod } = teamAndProjectResponse ;
1616
1717 const authResult : AuthorizationResult = {
1818 authorized : true ,
1919 team,
2020 project,
21+ authMethod,
2122 } ;
2223
24+ // if there's no project, we'll return the authResult (JWT or teamId auth)
2325 if ( ! project ) {
2426 return authResult ;
2527 }
2628
29+ if ( authMethod === "secretKey" ) {
30+ // if the auth was done using secreKey, we do not want to enforce domains or bundleIds
31+ return authResult ;
32+ }
33+
2734 // check for public restrictions
2835 if ( project . domains . includes ( "*" ) ) {
2936 return authResult ;
Original file line number Diff line number Diff line change @@ -148,5 +148,6 @@ export async function authorize(
148148 authorized : true ,
149149 team : teamAndProjectResponse . team ,
150150 project : teamAndProjectResponse . project ,
151+ authMethod : clientAuth . authMethod ,
151152 } ;
152153}
Original file line number Diff line number Diff line change @@ -5,7 +5,16 @@ export function authorizeService(
55 teamAndProjectResponse : TeamAndProjectResponse ,
66 serviceConfig : CoreServiceConfig ,
77) : AuthorizationResult {
8- const { team, project } = teamAndProjectResponse ;
8+ const { team, project, authMethod } = teamAndProjectResponse ;
9+
10+ if ( serviceConfig . serviceScope === null ) {
11+ // if explicitly set to null, we do not want to check for service level authorization
12+ return {
13+ authorized : true ,
14+ team,
15+ authMethod,
16+ } ;
17+ }
918
1019 if ( ! team . enabledScopes . includes ( serviceConfig . serviceScope ) ) {
1120 return {
@@ -21,6 +30,7 @@ export function authorizeService(
2130 return {
2231 authorized : true ,
2332 team,
33+ authMethod,
2434 } ;
2535 }
2636
@@ -57,5 +67,6 @@ export function authorizeService(
5767 authorized : true ,
5868 team,
5969 project,
70+ authMethod,
6071 } ;
6172}
Original file line number Diff line number Diff line change @@ -43,14 +43,15 @@ export const validTeamResponse: TeamResponse = {
4343 updatedAt : new Date ( "2024-06-01" ) ,
4444 billingPlan : "free" ,
4545 billingEmail :
"[email protected] " , 46- billingStatus : "noCustomer " ,
46+ billingStatus : "noPayment " ,
4747 growthTrialEligible : false ,
4848 enabledScopes : [ "storage" , "rpc" , "bundler" ] ,
4949} ;
5050
5151export const validTeamAndProjectResponse : TeamAndProjectResponse = {
5252 team : validTeamResponse ,
5353 project : validProjectResponse ,
54+ authMethod : "publishableKey" ,
5455} ;
5556
5657export const validServiceConfig : CoreServiceConfig = {
You can’t perform that action at this time.
0 commit comments